diesel: The trait bound `chrono::NaiveDateTime: diesel::Expression` is not satisfied
-
Which versions of Rust and Diesel are you using? Rust
1.18.0, Diesel0.13.0. -
Which feature flags are you using?
diesel = { version = "0.13", features = ["postgres", "chrono"] }
diesel_codegen = { version = "0.13", features = ["postgres"] }
chrono = { version = "0.4", features = ["serde"] }
serde = "1.0"
serde_derive = "1.0"
serde_json = "1.0"
- What are you trying to accomplish?
Trying to upgrade from Diesel 0.11, Serde 0.9 and Chrono 0.3 to the above versions.
- What is the full error you are seeing?
I’m seeing the following for each AsChangeset that uses chrono::NaiveDateTime:
error[E0277]: the trait bound `chrono::NaiveDateTime: diesel::Expression` is not satisfied
--> src/models/emails.rs:37:10
|
37 | #[derive(AsChangeset, Clone, Debug)]
| ^^^^^^^^^^^ the trait `diesel::Expression` is not implemented for `chrono::NaiveDateTime`
|
= note: required because of the requirements on the impl of `diesel::Expression` for `&chrono::NaiveDateTime`
= note: required because of the requirements on the impl of `diesel::expression::AsExpression<diesel::types::Timestamp>` for `&chrono::NaiveDateTime`
= note: this error originates in a macro outside of the current crate
- How can we reproduce this?
I think this should be reproducible with the above versions of Chrono and Diesel by having a table that has a column of type chrono::NaiveDateTime, then having an AsChangeset struct that tries to update said NaiveDateTime column.
I’m using NaiveDateTime in Rust for Postgres’ TIMESTAMP:
updated_at TIMESTAMP NOT NULL default now()
I’ve been going round in circles with this, but if it isn’t actually a Diesel issue then I apologise in advance. Thanks for all the work on Diesel, it’s excellent! 😃
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 8
- Comments: 22 (11 by maintainers)
@killercup You’re a gentleman and a scholar! Thanks so much for taking the time to help!
For anyone else who finds themselves here:
Add Diesel and co. as you would usually:
As @killercup said, replace the version of Diesel you’re using like so:
Run
cargo updateto make surer2d2-dieselis using the latest version of Diesel it can.Build.
Thanks again @killercup 😄
Does
cargo treegive you two diesel versions? I’d assume so, because r2d2-diesel uses the latest diesel, not its master branch.Maybe a better way to get this going is to not specify diesel master, but
0.13.0and addingThis replace every occurrence of diesel 0.13 in your dependency graph. (You might need to add the same lines for tje other diesel-* crates.)
lol 😅
@killercup a very good notice, I have just found this information too (about it’s master branch), but thanks for such a nice help here anyway!
@sgrif Actually, I use
0.14and0.14.1now and I have these errors:Thank you! I’m glad this works for you. With the next release of Diesel, 0.14, you should only need to increment the diesel and r2d2 version, remove the
[replace], and it should all just work™ 😃Very nice issue description! (We should steal this and make it a template!)
I think your problem stems from chrono recently yanking its 0.3.1 version and releasing 0.4 with serde 1.0 support instead (this was a breaking change in 0.3.1!). Diesel 0.13.0 does not support chrono 0.4. Which means two versions of chrono will be built, and they are not compatible to each other.
Can you try using diesel master instead?