Error caused by nullable varchar in diesel (database is PostgreSQL)

I'm using diesel.

I have this in my schema.rs:

table! {
    jobs (id) {
        id -> Int8,
        title -> Varchar,
        description -> Nullable<Varchar>,
    }
}

and it is generating this error:

16 |     let results = jobs.load::<models::Job>(&connection)
   |                        ^^^^ the trait `diesel::deserialize::FromSql<diesel::sql_types::Nullable<diesel::sql_types::Text>, _>` is not implemented for `*const str`

I believe I can resolve this by changing "pub description: String" below:

#[derive(Queryable)]
pub struct Job {
    pub id: i64,
    pub title: String,
    pub description: String,
}

What can do to resolve my problem? Please help! Thanks!

1 Like

Since it's nullable, description needs to be an Option<String>.

3 Likes

Thanks!

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.