Postgres sea orm: relation "table_name" does not exist at character 64

I have generated entities with the sea-orm-cli and I still get the error from Postgres relation "table_name" does not exist at character 64. I've tested it with psql and that works well.

pub async fn insert_user(user: user_service::User, role: Option<Role>) -> Result<Model, sea_orm::DbErr> {
    debug!("Insert new user");
    // Create new empty dataset for user data
    let user_data: subscriber_service::CacheEntry = user_service::create_user_val(&user.user_id).unwrap();
    let encoded_ud: String = hashing::encode(&user_data.to_string());

    // A role can be only student or teacher
    let role_check: Role = {
        if role.is_none() {
            Role::Student
        } else {
            Role::Teacher
        }
    };

    let class: i32;

    if let Err(_e) = get_class(user.class_name.clone()).await {
        debug!("Error finding class: {}", _e);
        insert_class(user.class_name.clone()).await?;
        let classes: Vec<class::Model> = get_class(user.class_name.clone()).await?;
        debug!("Classes: {:#?}", classes);
        class = classes.get(0).unwrap().id;
        debug!("Class: {}", &class);
    } else {
        let classes: Vec<class::Model> = get_class(user.class_name.clone()).await?;
        class = classes.get(0).unwrap().id;
    }
    
    let user: my_user::ActiveModel = my_user::ActiveModel {
        id: NotSet,
        user_id: sea_orm::ActiveValue::Set(user.user_id.clone()),
        pass_hash: sea_orm::ActiveValue::Set(user.password),
        salt: sea_orm::ActiveValue::Set(user.salt),
        user_data: sea_orm::ActiveValue::Set(Some(encoded_ud)),
        class_id: sea_orm::ActiveValue::Set(Some(class)),
        user_role: sea_orm::ActiveValue::Set(role_check),
        created_at: NotSet,
        modified_at: NotSet,
    };

    Ok(user.insert(&init().await).await?)
}

The table name is correct and I can see it with psql.

I found the error. It was a ConnectionOptions problem. I used .set_schema_search_path("my_schema") which I didn't needed because I set no specific schema.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.