I add a postgresql table net_test
like this:
CREATE TABLE public.net_test (
net inet NOT NULL,
id int8 NOT NULL,
CONSTRAINT net_pk PRIMARY KEY (id)
);
then add diesel model file like this which followed 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,
}
this is the schema file:
table! {
net_test (id) {
net -> Inet,
id -> Int8,
}
}
when I compile the project, shows error like this:
the trait `diesel::Expression` is not implemented for `IpNetwork`, which is required by `&'insert IpNetwork: AsExpression<diesel::sql_types::Inet>`
what should I do to fixed this issue? this is the diesel dependency config:
diesel = { version = "2.2.1", features = [
"postgres",
"64-column-tables",
"chrono",
"serde_json",
"numeric",
"ipnet-address"
] }
Enable the "network-address"
feature instead. The "ipnet-address"
feature is for enabling support for ipnet
types, but you aren't using that crate; you're using the ipnetwork
crate.