如何解决当我使用柴油 insert_into 数据到数据库时,为什么“找不到名为`execute`的方法”错误?
当我使用柴油“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;
。这意味着相应的特征不在范围内。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。