We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
Insert an active model and get back the last insert id doesn't work with autoincrement id.
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)] #[sea_orm(table_name = "fruit")] pub struct Model { #[sea_orm(primary_key)] pub id: i32, }
let pear = fruit::ActiveModel { ..Default::default() // just only autoincremented id here }; let res: InsertResult = Fruit::insert(pear).exec(db).await?;
It must insert and return saved id
It leads an error:
"Custom Error: Custom Error: Attribute id is NotSet"
All the time
Don't use static method and use such one instead:
let pear = fruit::ActiveModel { ..Default::default() }; let pear: fruit::Model = pear.insert(db).await?;
use sea_orm_migration::prelude::*; #[derive(DeriveMigrationName)] pub struct Migration; #[async_trait::async_trait] impl MigrationTrait for Migration { async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> { manager .create_table( Table::create() .table(Fruit::Table) .if_not_exists() .col( ColumnDef::new(Fruit::Id) .integer() .not_null() .auto_increment() .primary_key(), ) .to_owned(), ) .await } async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> { manager .drop_table(Table::drop().table(Fruit::Table).to_owned()) .await } } #[derive(DeriveIden)] enum Fruit { Table, Id, }
Generate a model based on migration above
Then try to insert entity using generated model:
0.12.14
The text was updated successfully, but these errors were encountered:
No branches or pull requests
Description
Insert an active model and get back the last insert id doesn't work with autoincrement id.
Steps to Reproduce
Expected Behavior
It must insert and return saved id
Actual Behavior
It leads an error:
Reproduces How Often
All the time
Workarounds
Don't use static method and use such one instead:
Reproducible Example
Generate a model based on migration above
Then try to insert entity using generated model:
Versions
0.12.14
The text was updated successfully, but these errors were encountered: