Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign upThe trait bound `chrono::NaiveDateTime: diesel::Expression` is not satisfied #968
Comments
This comment has been minimized.
|
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? diesel = { git = "https://github.com/diesel-rs/diesel", features = ["postgres", "chrono"] } |
This comment has been minimized.
Thanks :) If it turns out this is a problem with two chrono versions, you can use cargo-tree to see this more easily. |
This comment has been minimized.
elliotekj
commented
Jun 26, 2017
Ah, that's probably what the problem is then! I saw this line and assumed it did.
I wasn't expecting such a quick reply, I'll try it out as soon as I'm back at my work machine and let you know.
Thanks! I can't take credit for it though, I just filled in the details you ask for :) |
This comment has been minimized.
lol |
This comment has been minimized.
elliotekj
commented
Jun 26, 2017
|
Right. So Diesel's
Things I've tried:
use diesel::pg::PgConnection;
use r2d2;
use r2d2_diesel::ConnectionManager;
use std::env;
lazy_static! {
static ref CONNECTION: r2d2::Pool<ConnectionManager<PgConnection>> = {
let config = r2d2::Config::default();
let database_url = env::var("DATABASE_URL").expect("DATABASE_URL must be set");
let manager = ConnectionManager::<PgConnection>::new(database_url);
r2d2::Pool::new(config, manager).expect("Failed to create pool.")
};
}
pub fn connection() -> r2d2::Pool<ConnectionManager<PgConnection>> {
CONNECTION.clone()
}Feel free to close this when it gets too off topic from the original issue / becomes too specific to just how I'm using it. |
This comment has been minimized.
|
Does Maybe a better way to get this going is to not specify diesel master, but
This replace every occurrence of diesel 0.13 in your dependency graph. (You might need to add the same lines for tje other diesel-* crates.) |
This comment has been minimized.
elliotekj
commented
Jun 26, 2017
|
@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 Build. Thanks again @killercup |
This comment has been minimized.
|
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 |
killercup
closed this
Jun 26, 2017
This comment has been minimized.
elliotekj
commented
Jul 5, 2017
|
Just confirming that Diesel |
This comment has been minimized.
|
Thanks for confirming. |
This comment has been minimized.
vityafx
commented
Jul 11, 2017
•
|
@sgrif Actually, I use
#[derive(Debug, Clone, Queryable, Identifiable, Insertable, Associations, AsChangeset, Serialize, Deserialize)]
#[table_name = "phones"]
#[primary_key(imei)]
#[belongs_to(User)]
pub struct Phone {
pub imei: i64,
pub model: String,
pub vendor: String,
pub manufacturer: String,
pub last_sync: NaiveDateTime, // In UTC
pub user_id: i32,
}[dependencies]
rocket = "0.2.8"
rocket_codegen = "0.2.8"
rocket_contrib = "0.2.8"
serde = "0.9"
serde_derive = "0.9"
serde_json = "0.9"
r2d2 = "0.7.2"
r2d2-diesel = "0.14"
chrono = { version = "0.4", features = ["serde"] }
[dependencies.diesel]
version = "0.14"
default-features = false
features = ["sqlite", "chrono"]
[dependencies.diesel_codegen]
version = "0.14"
default-features = false
features = ["sqlite"] |
This comment has been minimized.
|
@vityafx these look like serde issues—most likely because you are using serde 0.9 and chrono requires 1.0. |
This comment has been minimized.
vityafx
commented
Jul 11, 2017
•
|
@killercup oh well, yes, totally forgot about that but I did knew that! :-D Just rocket uses old serde, this is the problem, I guess, but I can't change it :( Thanks. |
This comment has been minimized.
|
Rocket 0.3 will include it: SergioBenitez/Rocket#273 (comment) Maybe you can use rocket's master branch until then? |
This comment has been minimized.
vityafx
commented
Jul 11, 2017
|
@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! |
This comment has been minimized.
greenpdx
commented
Nov 25, 2017
•
|
I have read this and I still do not understand the fix. I have a postgress table with a TIMESTAMP column. error[E0277]: the trait bound error: aborting due to previous error |
This comment has been minimized.
|
@greenpdx Your issue is slightly different than that one described here. You are trying to load a nullable sql type ( |
elliotekj commentedJun 26, 2017
Which versions of Rust and Diesel are you using?
Rust
1.18.0, Diesel0.13.0.Which feature flags are you using?
Trying to upgrade from Diesel
0.11, Serde0.9and Chrono0.3to the above versions.I'm seeing the following for each
AsChangesetthat useschrono::NaiveDateTime: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 anAsChangesetstruct that tries to update saidNaiveDateTimecolumn.I'm using
NaiveDateTimein Rust for Postgres'TIMESTAMP: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! :)