Problem:
When I tried to map the model with date and time field, I got this compiler error:
error[E0277]: the trait bound `(Integer, Datetime):
load_dsl::private::CompatibleType<myapp::models::MyModel, _>`
is not satisfied
From this set of model and schema:
// models.rs
pub struct MyModel {
pub id: i32,
pub created_at: NaiveDateTime,
}
// schema.rs
diesel::table! {
my_table (id) {
id -> Integer,
created_at -> Datetime,
}
}
Solution:
Fortunately, I found the document mentioned about the DateTime field.
So we just need to put the feature "chrono"
to enable it.
# Cargo.toml
diesel = { version = "2.0.0", features = ["mysql", "chrono"] }
And it works! ✅ 🎉
Tips:
For JSON field, you will also need the serde_json
feature in Cargo.toml.
diesel = { version = "2.0.0", features = ["mysql", "chrono", "serde_json"] }
Top comments (0)