-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[E0277]: the trait bound i32: diesel::types::FromSqlRow<diesel::types::Nullable<diesel::types::Integer>, diesel::pg::Pg>
is not satisfied
#330
Comments
I use ubuntu 15.10, and the version of rust is: fuying@fuying-linux:~/rustprojs/simtraining$ rustc --version
rustc 1.10.0-nightly (d91f8ab0f 2016-05-07)
fuying@fuying-linux:~/rustprojs/simtraining$ cargo --version
cargo 0.11.0-nightly (b304305 2016-05-06)
cargo.toml: [package]
name = "simtraining"
version = "0.1.0"
authors = ["fuying"]
[dependencies]
time = "^0.1"
rand = "^0.3"
libc = "^0.2"
mio = "^0.5"
serde = "^0.7.0"
serde_json = "^0.7.0"
serde_macros = "^0.7.0"
iron = "^0.3.0"
router = "^0.1.1"
diesel = { git = "https://github.com/diesel-rs/diesel.git" }
diesel_codegen = { git = "https://github.com/diesel-rs/diesel.git", default-features = false, features = ["nightly", "postgres"] }
dotenv = "^0.8.0"
dotenv_macros = "^0.8.0"
[dev-dependencies]
rand = "^0.3"
[target.x86_64-pc-windows-msvc.dependencies]
winapi = "^0.2"
ws2_32-sys = "^0.2"
[target.x86_64-pc-windows-gnu.dependencies]
winapi = "^0.2"
ws2_32-sys = "^0.2"
[target.i686-pc-windows-msvc.dependencies]
winapi = "^0.2"
ws2_32-sys = "^0.2"
[[example]]
name = "test-router"
path = "examples/testrouter.rs"
[[example]]
name = "test-create-user"
path = "examples/testcreateuser.rs"
|
This is correct. You cannot deserialize a column of type |
@sgrif |
@sgrif #[derive(Queryable)] Does it correct? Because I am outside and can't test it. So if you are not busy, please help me. |
We don't really have support for embedded structs at the moment. When you're querying against two tables, you'd get back a use diesel::prelude::*;
use diesel::backend::Backend;
use diesel::types::{FromSqlRow + HasSqlType};
use diesel::row::Row;
use std::error::Error;
impl<ST, DB> FromSqlRow<ST, DB> for User where
DB: Backend + HasSqlType<ST>,
User: Queryable<ST, DB>,
<User as Queryable<ST, DB>>::Row: FromSqlRow<ST, DB>,
{
fn build_from_row<T: Row<DB>>(row: &mut T) -> Result<Self, Box<Error + Send + Sync>> {
let row = try!(<<User as Queryable<ST, DB>>::Row as FromSqlRow<ST, DB>>::build_from_row(row));
Ok(User::build(row))
}
} Note: Haven't tried that exact code, that's just from memory of what it'd roughly look like. We don't support the JSON type yet, but it's on the radar for something we'd like to support. #44 is the tracking issue, and I've mentioned how you could use it today in your app if needed in the comments there. |
@sgrif |
1 similar comment
@sgrif |
Just a note, I faced similar issue. it's important that after you've made changes to the migration, run
From my limited understanding, I assume the custom code generator does not update the generated code and uses the old database definition, So we need to clean the generated code I am sorry, for least clear explanation as I'm sleepy and just figured out the problem. I hope it helps someone. |
@tmahmood thank you :) your solution solved my issue |
If you ever land here looking for solution to not implemented traits compilation errors make sure that your model declaration fields follow exact order of fields in your table. |
This solution solves my issue! Thanks!! |
@mplebanski Thank you for your comment! I have tried to understand and solve a similar issue for an hour now, and randomly I saw your comment which fixed it all 🎉 I simply changed the field order in my struct to match my That the field order matters should be written in capital letters somewhere. |
@skovmand That is already mentioned in multiple locations like the getting started guide or the documentation of the |
Thank you for the reference, which explains it clearly 👍 . Perhaps I was overwhelmed by new information :-) |
I owe you lunch. |
Hello, when I try to use diesel to build my first orm, and error is come. My way is exactly same to your getting-start doc.
up.sql:
down.sql:
.env:
and the command
diesel migration redo
has been executed successfully :fuying@fuying-linux:~/rustprojs/simtraining$ diesel migration redo Rolling back migration 20160514210851 Running migration 20160514210851
lib.rs:
schema.rs:
user.rs:
The text was updated successfully, but these errors were encountered: