【发布时间】:2020-12-21 01:53:14
【问题描述】:
我正在尝试使用柴油和 mysql 建立模型。我的第一个模型编译没有问题,但是当我的第二个模型(用于向我的数据库插入新条目的模型)尝试派生 Insertable 时,我收到大量错误,指出柴油不能使用 f64、u16 ,或NaiveDateTime
error[E0277]: the trait bound `u16: diesel::Expression` is not satisfied
--> src/models.rs:26:10
|
26 | #[derive(Insertable, Debug, Queryable)]
| ^^^^^^^^^^ the trait `diesel::Expression` is not implemented for `u16`
|
= note: required because of the requirements on the impl of `diesel::expression::AsExpression<diesel::sql_types::Unsigned<diesel::sql_types::Integer>>` for `u16`
= note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0277]: the trait bound `chrono::naive::datetime::NaiveDateTime: diesel::Expression` is not satisfied
--> src/models.rs:26:10
|
26 | #[derive(Insertable, Debug, Queryable)]
| ^^^^^^^^^^ the trait `diesel::Expression` is not implemented for `chrono::naive::datetime::NaiveDateTime`
|
= note: required because of the requirements on the impl of `diesel::expression::AsExpression<diesel::sql_types::Date>` for `chrono::naive::datetime::NaiveDateTime`
= note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0277]: the trait bound `f64: diesel::Expression` is not satisfied
--> src/models.rs:26:10
|
26 | #[derive(Insertable, Debug, Queryable)]
| ^^^^^^^^^^ the trait `diesel::Expression` is not implemented for `f64`
|
= note: required because of the requirements on the impl of `diesel::expression::AsExpression<diesel::sql_types::Float>` for `f64`
= note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0277]: the trait bound `u16: diesel::Expression` is not satisfied
--> src/models.rs:26:10
|
26 | #[derive(Insertable, Debug, Queryable)]
| ^^^^^^^^^^ the trait `diesel::Expression` is not implemented for `u16`
|
= note: required because of the requirements on the impl of `diesel::Expression` for `&u16`
= note: required because of the requirements on the impl of `diesel::expression::AsExpression<diesel::sql_types::Unsigned<diesel::sql_types::Integer>>` for `&u16`
= note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0277]: the trait bound `chrono::naive::datetime::NaiveDateTime: diesel::Expression` is not satisfied
--> src/models.rs:26:10
|
26 | #[derive(Insertable, Debug, Queryable)]
| ^^^^^^^^^^ the trait `diesel::Expression` is not implemented for `chrono::naive::datetime::NaiveDateTime`
|
= note: required because of the requirements on the impl of `diesel::Expression` for `&chrono::naive::datetime::NaiveDateTime`
= note: required because of the requirements on the impl of `diesel::expression::AsExpression<diesel::sql_types::Date>` for `&chrono::naive::datetime::NaiveDateTime`
= note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0277]: the trait bound `f64: diesel::Expression` is not satisfied
--> src/models.rs:26:10
|
26 | #[derive(Insertable, Debug, Queryable)]
| ^^^^^^^^^^ the trait `diesel::Expression` is not implemented for `f64`
|
= note: required because of the requirements on the impl of `diesel::Expression` for `&f64`
= note: required because of the requirements on the impl of `diesel::expression::AsExpression<diesel::sql_types::Float>` for `&f64`
= note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0277]: the trait bound `u16: diesel::Expression` is not satisfied
--> src/models.rs:26:10
|
26 | #[derive(Insertable, Debug, Queryable)]
| ^^^^^^^^^^ the trait `diesel::Expression` is not implemented for `u16`
|
= note: required because of the requirements on the impl of `diesel::Expression` for `&'insert u16`
= note: required because of the requirements on the impl of `diesel::expression::AsExpression<diesel::sql_types::Unsigned<diesel::sql_types::Integer>>` for `&'insert u16`
= note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0277]: the trait bound `chrono::naive::datetime::NaiveDateTime: diesel::Expression` is not satisfied
--> src/models.rs:26:10
|
26 | #[derive(Insertable, Debug, Queryable)]
| ^^^^^^^^^^ the trait `diesel::Expression` is not implemented for `chrono::naive::datetime::NaiveDateTime`
|
= note: required because of the requirements on the impl of `diesel::Expression` for `&'insert chrono::naive::datetime::NaiveDateTime`
= note: required because of the requirements on the impl of `diesel::expression::AsExpression<diesel::sql_types::Date>` for `&'insert chrono::naive::datetime::NaiveDateTime`
= note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0277]: the trait bound `f64: diesel::Expression` is not satisfied
--> src/models.rs:26:10
|
26 | #[derive(Insertable, Debug, Queryable)]
| ^^^^^^^^^^ the trait `diesel::Expression` is not implemented for `f64`
|
= note: required because of the requirements on the impl of `diesel::Expression` for `&'insert f64`
= note: required because of the requirements on the impl of `diesel::expression::AsExpression<diesel::sql_types::Float>` for `&'insert f64`
= note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info)
这是我的 models.rs 文件
use crate::schema::*;
use serde::{Deserialize, Serialize};
use chrono::NaiveDateTime;
#[derive(Debug, Serialize, Deserialize, Queryable)]
pub struct Site {
pub site_id: i32,
pub name: String,
pub slug: String,
pub rack_size: u16,
pub date_created: chrono::NaiveDateTime,
pub latitude: f64,
pub longitude: f64
}
//#[derive(Insertable, Debug, Queryable)]
//#[table_name = "site"]
//pub struct NewSite<'a> {
// pub name: &'a str,
// pub slug: &'a str,
// pub rack_size: &'a u16,
// pub date_created: chrono::NaiveDateTime,
// pub latitude: &'a f64,
// pub longitude: &'a f64
//}
#[derive(Insertable, Debug, Queryable)]
#[table_name = "site"]
pub struct NewSite {
pub name: String,
pub slug: String,
pub rack_size: u16,
pub date_created: chrono::NaiveDateTime,
pub latitude: f64,
pub longitude: f64
}
还有我的 Cargo.toml
[package]
name = "micd"
version = "0.1.0"
authors = ["First Last <no@gmail.com>"]
edition = "2018"
[dependencies]
actix-web = "2.0.0"
actix-web-httpauth = { git = "https://github.com/actix/actix-web-httpauth" }
chrono = { version = "0.4.10", features = ["serde"] }
derive_more = "0.99.2"
diesel = { version = "1.4.2", features = ["extras", "mysql", "default"] }
dotenv = "0.15.0"
futures = "0.3.1"
r2d2 = "0.8.8"
serde = "1.0"
serde_derive = "1.0"
serde_json = "1.0"
actix-service = "1.0.1"
alcoholic_jwt = "1.0.0"
reqwest = "0.9.22"
actix-rt = "1.0.0"
我已尝试按照the only SO question I could find that relates to this 的建议在柴油中导入数字功能。我看过的所有指南都只是跳过了这个问题,我看不出我可能做错了什么。
【问题讨论】:
标签: mysql rust rust-diesel