-
DescriptionWhen using String as primary key "Execution Error: Failed to find inserted item" appears. Steps to ReproduceEntity model: use sea_orm::prelude::*;
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Deserialize, Serialize)]
#[sea_orm(table_name = "clients")]
pub struct Model {
#[sea_orm(primary_key)]
pub id: String,
pub name: String,
pub surname: String,
pub nip_prefix: i32,
pub nip: String,
pub state: String,
pub postcode: String,
pub locality: String,
pub street: String,
pub house_nb: i32,
}
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {}
impl ActiveModelBehavior for ActiveModel {} actix web function: pub async fn add(pool: Data<DatabaseConnection>, json: Json<client::Model>) -> HttpResponse {
let pool = pool.as_ref();
let json: client::ActiveModel = json.0.into();
let res = json.insert(pool).await;
if let Err(err) = res {
println!("{err}");
HttpResponse::InternalServerError().body(err.to_string())
} else {
HttpResponse::Ok().finish()
}
} Expected BehaviorIf 'json' model is correct it should be inserted to db and 'res' should not return Err. Actual BehaviorWild "Execution Error: Failed to find inserted item" appears when 'json' model is correct. More interestingly item is correctly inserted into database. Problem is with retrieving the inserted item. Reproduces How Oftenalways Versions├── sea-orm v0.6.0 Mysql + Windows Additional InformationProblem disappears when disabling auto_increment: pub struct Model {
#[sea_orm(primary_key, auto_increment = false)]
pub id: String,
pub name: String,
pub surname: String,
pub nip_prefix: i32,
pub nip: String,
pub state: String,
pub postcode: String,
pub locality: String,
pub street: String,
pub house_nb: i32,
} Sorry for my poor english. |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments
-
Hey @xodix, welcome! I wonder why the |
Beta Was this translation helpful? Give feedback.
-
And, is the |
Beta Was this translation helpful? Give feedback.
-
Some primary keys are meant to be representation of ID codes found in an ID card or a passport. |
Beta Was this translation helpful? Give feedback.
-
I am working with an existing database not generated by SeaORM. |
Beta Was this translation helpful? Give feedback.
-
Ok, the |
Beta Was this translation helpful? Give feedback.
Ok, the
id
column does not auto increment on its own. So, it normal to specify#[sea_orm(auto_increment = false)]
on the Model.