rust-diesel - why "no method named `execute` found" error have when i use diesel insert_into data to database?
问题描述
I have a problem when i use diesel "insert_into" insert data to database, any one can help me?
error:
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, diesel::expression::bound::Bound<diesel::sql_types::Text, &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;
code:
diesel::insert_into(post::table)
.values(&post)
.execute(&*conn);
}
schema:
table! {
post (id) {
id -> Integer,
username -> Varchar,
postdata -> Varchar,
}
}
解决方案
正如编译器错误消息告诉您的那样,您错过了use crate::diesel::RunQueryDsl;
当前模块中的 a 。这意味着相应的特征不在范围内。
推荐阅读
- python - 不断收到错误消息“已超出未经验证使用的每日限制。继续使用需要注册。”
- javascript - 如何将网站链接添加到随机图像生成器
- python - Azure CLI:UnicodeEncodeError:'ascii'编解码器无法在位置 598 编码字符 u'\u2018':序数不在范围内(128)
- javascript - moment.js 给出了不正确的差异
- python - 如何检查坐标变换是否有效?
- python - 从 MySQL DB 中的文本区域插入文本(Python/Flask)
- javascript - 获取 VSCode 以识别变量正在不同的 javascript 文件中使用
- mysql - 来自多个表的总和的数据透视表
- javascript - 我有 3 个 div,如何通过单击(一个接一个)选择 2 个 div 并在 Javascript 中不显示(或其他)第三个
- java - 二叉树 - 如何删除元素;爪哇