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 · 3 comments

Comments

Projects
None yet
2 participants
@ghost

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

This comment has been minimized.

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

This comment has been minimized.

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 Feb 10, 2018

@ghost

This comment has been minimized.

ghost commented Feb 11, 2018

Thanks,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment