我添加了一个 postgresql 表
net_test
,如下所示:
CREATE TABLE public.net_test (
net inet NOT NULL,
id int8 NOT NULL,
CONSTRAINT net_pk PRIMARY KEY (id)
);
然后添加柴油模型文件,如下所示https://docs.diesel.rs/2.1.x/diesel/pg/sql_types/struct.Inet.html:
use std::fmt::Display;
use serde::Serialize;
use serde::Deserialize;
use crate::model::diesel::dolphin::dolphin_schema::*;
use bigdecimal::BigDecimal;
use chrono::DateTime;
use chrono::offset::Utc;
use ipnetwork::IpNetwork;
#[derive(Insertable,Queryable,QueryableByName,Debug,Serialize,Deserialize,Default,Clone)]
#[diesel(table_name = net_test)]
pub struct NetTest {
pub net: IpNetwork,
pub id: i64,
}
这是架构文件:
table! {
net_test (id) {
net -> Inet,
id -> Int8,
}
}
当我编译项目时,显示如下错误:
the trait `diesel::Expression` is not implemented for `IpNetwork`, which is required by `&'insert IpNetwork: AsExpression<diesel::sql_types::Inet>`
我应该怎么做才能解决这个问题?这是柴油依赖配置:
diesel = { version = "2.2.1", features = [
"postgres",
"64-column-tables",
"chrono",
"serde_json",
"numeric",
"ipnet-address"
] }