首页 > 解决方案 > 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,
    }
}

标签: rust-dieselrust-rocket

解决方案


正如编译器错误消息告诉您的那样,您错过了use crate::diesel::RunQueryDsl;当前模块中的 a 。这意味着相应的特征不在范围内。


推荐阅读