New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Please help me to understand diesel error #1682

Closed
ivmazurenko opened this Issue May 6, 2018 · 0 comments

Comments

Projects
None yet
1 participant
@ivmazurenko

ivmazurenko commented May 6, 2018

Hi, can you help me a little?

I have a simple model:

#[derive(Insertable)]
#[table_name = "TodoItems"]
pub struct InsertableTodoItem {
    pub content: String,
    pub user_id: i32
}

And a simple schema:

table! {
    TodoItems (id) {
        id -> Integer,
        user_id -> Integer,
        content -> Text,
    }
}

table! {
    Users (id) {
        id -> Integer,
        first_name -> Text,
        last_name -> Text,
        email -> Text,
        password -> Text,
    }
}

allow_tables_to_appear_in_same_query!(
    TodoItems,
    Users,
);

My model created with next migration

CREATE TABLE TodoItems (
  id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
  user_id INTEGER NOT NULL references User (id),
  content TEXT NOT NULL
)

After i try to insert a new item with next code:

let insertable_todo_item = InsertableTodoItem { ... };

diesel::insert_into(TodoItems::table)
    .values(insertable_todo_item)
    .execute(&sqlite_connection)
    .expect("Error saving new todo item")

I've got a annoying unreadable error:

error[E0277]: the trait bound `model::todo_item::InsertableTodoItem: diesel::Insertable<data::schema::TodoItems::table>` is not satisfied
  --> src/data/todo_item.rs:50:10
   |
50 |         .values(insertable_todo_item)
   |          ^^^^^^ the trait `diesel::Insertable<data::schema::TodoItems::table>` is not implemented for `model::todo_item::InsertableTodoItem`
   |
   = help: the following implementations were found:
             <&'insert model::todo_item::InsertableTodoItem as diesel::Insertable<data::schema::TodoItems::table>>

error[E0275]: overflow evaluating the requirement `<_ as diesel::Column>::Table`
  --> src/data/todo_item.rs:51:10
   |
51 |         .execute(&sqlite_connection)
   |          ^^^^^^^
   |
   = help: consider adding a `#![recursion_limit="128"]` attribute to your crate
   = note: required because of the requirements on the impl of `diesel::Insertable<data::schema::TodoItems::table>` for `(&_, &_, &_, &_, &_, &_)`
   = note: required because of the requirements on the impl of `diesel::Insertable<data::schema::TodoItems::table>` for `&(_, _, _, _, _, _)`
   = note: required because of the requirements on the impl of `diesel::Insertable<data::schema::TodoItems::table>` for `(&(_, _, _, _, _, _), &_, &_, &_, &_, &_)`
   = note: required because of the requirements on the impl of `diesel::Insertable<data::schema::TodoItems::table>` for `&((_, _, _, _, _, _), _, _, _, _, _)`
   = note: required because of the requirements on the impl of `diesel::Insertable<data::schema::TodoItems::table>` for `(&((_, _, _, _, _, _), _, _, _, _, _), &_, &_, &_, &_, &_)`
   = note: required because of the requirements on the impl of `diesel::Insertable<data::schema::TodoItems::table>` for `&(((_, _, _, _, _, _), _, _, _, _, _), _, _, _, _, _)`
   = note: required because of the requirements on the impl of `diesel::Insertable<data::schema::TodoItems::table>` for `(&(((_, _, _, _, _, _), _, _, _, _, _), _, _, _, _, _), &_, &_, &_, &_, &_)`
   = note: required because of the requirements on the impl of `diesel::Insertable<data::schema::TodoItems::table>` for `&((((_, _, _, _, _, _), _, _, _, _, _), _, _, _, _, _), _, _, _, _, _)`

   How can i fix it? Where can i ask a question next time?

@ivmazurenko ivmazurenko closed this May 6, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment