问题描述
当我使用柴油“insert_into”向数据库插入数据时遇到问题,有人可以帮助我吗?
错误:
6 | .execute(&*conn);
| ^^^^^^^ method not found in `InsertStatement<table,ValuesClause<(ColumnInsertValue<columns::id,diesel::expression::bound::Bound<diesel::sql_types::Integer,&i32>>,ColumnInsertValue<columns::username,diesel::expression::bound::Bound<diesel::sql_types::Text,&std::string::String>>,ColumnInsertValue<columns::postdata,&std::string::String>>),table>>`
|
= help: items from traits can only be used if the trait is in scope
= note: the following trait is implemented but not in scope; perhaps add a `use` for it:
`use crate::diesel::RunQueryDsl;
代码:
diesel::insert_into(post::table)
.values(&post)
.execute(&*conn);
}
架构:
table! {
post (id) {
id -> Integer,username -> Varchar,postdata -> Varchar,}
}
解决方法
正如编译器错误消息告诉您的那样,您在当前模块中遗漏了一个 use crate::diesel::RunQueryDsl;
。这意味着相应的特征不在范围内。