schema.rs中table字段的顺序必需要与struct中的字段顺序一致。
例如
/// schema.rs
diesel::table! {
role (id) {
id -> Unsigned<Bigint>,
#[max_length = 255]
name -> Nullable<Varchar>,
#[max_length = 255]
key_ -> Varchar,
description -> Nullable<Text>,
del_flag -> Unsigned<Tinyint>,
create_time -> Timestamp,
update_time -> Timestamp,
}
}
/// role.rs
#[derive(Debug,Queryable, Serialize, Deserialize)]
#[diesel(table_name = role)]
pub struct Role {
pub id: u64,
/// 名称
pub name: Option<String>,
/// 角色的标识
pub key_: String,
/// 备注信息
pub description: Option<String>,
/// 实体逻辑删除标识:1删除,0正常
pub del_flag: u8,
/// 数据创建时间
pub create_time: NaiveDateTime,
/// 数据更新时间
pub update_time: NaiveDateTime,
}
否则会产生如下错误
Trait `FromStaticSqlRow<(Unsigned<BigInt>, Nullable<Text>, Text, Nullable<Text>, Unsigned<TinyInt>, Timestamp, Timestamp), Mysql>` is not implemented for `(u64, Option<String>, String, u8, Option<String>, NaiveDateTime, NaiveDateTime)` [E0277]