Diesel trait bound not satisfied

Hello everyone,

I'm trying to filter some data of a table depending on a struct called Filter. When I use .load() I get this enormous error:

error[E0277]: the trait bound `(diesel::sql_types::Integer, diesel::sql_types::Text, diesel::sql_types::Integer, diesel::sql_types::Text, diesel::sql_types::Bool, diesel::sql_types::Text, diesel::sql_types::Integer, diesel::sql_types::Integer, diesel::sql_types::Text, diesel::sql_types::Bool, diesel::sql_types::Timestamp, diesel::sql_types::Bool, diesel::sql_types::Bool, diesel::sql_types::Nullable<diesel::sql_types::Text>): load_dsl::private::CompatibleType<Question, Mysql>` is not satisfied
    --> src/question.rs:172:55
     |
172  |         .filter(subject.eq("mates")).load::<Question>(&mut conn)?;
     |                                      ----             ^^^^^^^^^ the trait `load_dsl::private::CompatibleType<Question, Mysql>` is not implemented for `(diesel::sql_types::Integer, diesel::sql_types::Text, diesel::sql_types::Integer, diesel::sql_types::Text, diesel::sql_types::Bool, diesel::sql_types::Text, diesel::sql_types::Integer, diesel::sql_types::Integer, diesel::sql_types::Text, diesel::sql_types::Bool, diesel::sql_types::Timestamp, diesel::sql_types::Bool, diesel::sql_types::Bool, diesel::sql_types::Nullable<diesel::sql_types::Text>)`
     |                                      |
     |                                      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 `SelectStatement<FromClause<table>, DefaultSelectClause<FromClause<table>>, NoDistinctClause, WhereClause<Grouped<Eq<subject, Bound<Text, &str>>>>>` to implement `LoadQuery<'_, _, Question>`
     = note: the full type name has been written to '/home/juanjo/Documentos/ProgramaciĆ³n/trivial_packager/target/debug/deps/trivial_packager-969823c3fda829c5.long-type-1694249202718504701.txt'
note: required by a bound in `diesel::RunQueryDsl::load`
    --> /home/juanjo/.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 `RunQueryDsl::load`

This is the affected part of the code, the full code is here:

fn filter_question_query(filter: Filter, pool: web::Data<Pool>) -> Result<Vec<Question>, ServiceError> {
    use crate::schema::questions::dsl::*;

    let mut conn = pool.get()?;

    let data = questions
        .filter(subject.eq("mates")).load::<Question>(&mut conn)?;

    Ok(data)
}

A part of the schema.rs for MySqlDB:

diesel::table! {
    questions (id) {
        id -> Integer,
        subject -> Varchar,
        level -> Integer,
        question -> Varchar,
        hide -> Bool,
        answers -> Varchar,
        tries -> Integer,
        time -> Integer,
        image -> Varchar,
        bigger -> Bool,
        created_at -> Timestamp,
        verified -> Bool,
        modified -> Bool,
        creator -> Nullable<Varchar>,
    }
}

This issue doesn't happen on other parts of the code while they have in essence the same code.

Question is missing the id field and its creator is String but Nullable<Varchar> in the schema which isn't compatible. From the docs of the Queryable derive macro (Queryable in diesel::prelude - Rust):

Note: When this trait is derived, it will assume that all fields on your struct matches all fields in the query, including the order and count. This means that field order is significant if you are using #[derive(Queryable)]. Field name has no effect.

Thank you very much Helizoa.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.