Trait bound not satisfied in diesel rust

344 Views Asked by At

Hello i load the content of a table in a vec with diesel and mysql

fn establish_connection() -> MysqlConnection {
    dotenv().ok();
    let database_url = env::var("DATABASE_URL")
        .expect("DATABASE_URL must be set");
      MysqlConnection::establish(&database_url)
        .expect(&format!("Error connecting to {}", database_url))
}

pub fn mostra_richieste() -> String{
    let mut result_vec = vec![];
    let connection = establish_connection();
    let results = richieste
        .load::<Richieste>(&mut connection)
        .expect("Error loading posts");

    println!("Found {} elemets", results.len());

    for p in results {
        result_vec.push(p);
    };
    let mut str = "".to_string();
    if result_vec.len() > 0 {
        str = serde_json::to_string(&result_vec).unwrap();
    } else {
        str = "{ \"warning\": \"nessuna richiesta trovata\" }".to_string()
    };

    str.to_string()
}

befeore it worked but suddenly on the .looad method the connection doesn't work anymore

.load::(&mut connection)

error is :

error[E0277]: the trait bound `(diesel::sql_types::Integer, diesel::sql_types::Nullable<Text>, diesel::sql_types::Nullable<Text>, diesel::sql_types::Nullable<Text>, diesel::sql_types::Nullable<Text>, diesel::sql_types::Nullable<Text>, diesel::sql_types::Nullable<Text>, diesel::sql_types::Nullable<Text>, diesel::sql_types::Nullable<diesel::sql_types::Bool>): load_dsl::private::CompatibleType<models::Richieste, Mysql>` is not satisfied
    --> src/database/mod.rs:23:28
     |
23   |         .load::<Richieste>(&mut connection)
     |          ----              ^^^^^^^^^^^^^^^ the trait `load_dsl::private::CompatibleType<models::Richieste, Mysql>` is not implemented for `(diesel::sql_types::Integer, diesel::sql_types::Nullable<Text>, diesel::sql_types::Nullable<Text>, diesel::sql_types::Nullable<Text>, diesel::sql_types::Nullable<Text>, diesel::sql_types::Nullable<Text>, diesel::sql_types::Nullable<Text>, diesel::sql_types::Nullable<Text>, diesel::sql_types::Nullable<diesel::sql_types::Bool>)`
     |          |
     |          required by a bound introduced by this call
     |
     = help: the following other types implement trait `load_dsl::private::CompatibleType<U, DB>`:
               (ST0, ST1)
               (ST0, ST1, ST2)
               (ST0, ST1, ST2, ST3)
               (ST0, ST1, ST2, ST3, ST4)
               (ST0, ST1, ST2, ST3, ST4, ST5)
               (ST0, ST1, ST2, ST3, ST4, ST5, ST6)
               (ST0, ST1, ST2, ST3, ST4, ST5, ST6, ST7)
               (ST0, ST1, ST2, ST3, ST4, ST5, ST6, ST7, ST8)
             and 24 others
     = note: required for `table` to implement `LoadQuery<'_, _, models::Richieste>`
note: required by a bound in `diesel::RunQueryDsl::load`
    --> /home/erty/.cargo/registry/src/github.com-1ecc6299db9ec823/diesel-2.0.3/src/query_dsl/mod.rs:1499:15
     |
1499 |         Self: LoadQuery<'query, Conn, U>,
     |               ^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `diesel::RunQueryDsl::load

i have tried to check my srtuct but they are right, this error occurred when i delete the db and created a new one with diesel setup and then the migration generation

1

There are 1 best solutions below

0
On

I Solved this doing

diesel migration redo