Skip to content
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

Problem:something wrong with official guide. #1551

Closed
ghost opened this issue Feb 10, 2018 · 4 comments
Closed

Problem:something wrong with official guide. #1551

ghost opened this issue Feb 10, 2018 · 4 comments

Comments

@ghost
Copy link

ghost commented Feb 10, 2018

Versions

  • Rust: Nightly
  • Diesel: 1.0.0
  • Database: MySQL5.7
  • Operating System OSX

Problem Description

Follow Official Guide,When I Finished **show_posts.rs**,and I execute **cargo run --bin show_posts**,a error occurs.

--> src/bin/show_posts.rs:14:10
|
14 | .load::(&connection)
| ^^^^ the trait diesel::deserialize::FromSql<diesel::sql_types::BigInt, diesel::mysql::Mysql> is not implemented for i32
|

What does this mean?
How can I solve it?

Thanks very much.

@brandur
Copy link
Contributor

brandur commented Feb 10, 2018

diesel::sql_types::BigInt is representative of the BIGINT SQL type. You can see from the MySQL documentation on integer types here that BIGINT is an 8-byte integer. That's inherently incompatible with an i32 which is 32 bits (or 4 bytes), and Diesel is smart enough to understand that there's a potentially unsafe condition when you try to load a BIGINT that's too large into an i32, and won't let your program compile.

Solution: try i64 (64 bits, or 8 bytes) instead.

(Disclaimer: I'm not a maintainer of this project, but hopefully this is helpful.)

@sgrif
Copy link
Member

sgrif commented Feb 10, 2018

Above comment is correct. Either use i64 on the Rust side, or change the type to INTEGER on the SQL side.

@sgrif sgrif closed this as completed Feb 10, 2018
@ghost
Copy link
Author

ghost commented Feb 11, 2018

Thanks,

@cjen07
Copy link

cjen07 commented Nov 21, 2018

Thanks, just solved my problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants