SeaQL / sea-orm

🐚 An async & dynamic ORM for Rust
https://www.sea-ql.org/SeaORM/
Apache License 2.0
7.03k stars 493 forks source link

SeaORM issue with UUID stored as binary(16) in MySQL #2108

Closed itsbalamurali closed 7 months ago

itsbalamurali commented 7 months ago

I'm using SeaORM in my Rust project and I've encountered an issue when trying to use a UUID as a primary key. MySQL database stores the UUID as binary(16), but it seems like SeaORM is having trouble handling this. Here's the relevant part of my model:

#[derive(Clone, Debug, PartialEq, DeriveEntityModel)]
#[sea_orm(table_name = "users")]
pub struct Model {
    #[sea_orm(primary_key)]
    pub id: Uuid,
    // other fields...
}

And here's how I'm creating a new user:

pub async fn create_user(
    db: &DbConn,
    // other fields...
) -> Result<Model, DbErr> {
    let user_id = Uuid::new_v4();
    let user = ActiveModel {
        id: Set(user_id.to_owned()),
        // other fields...
    };

    // rest of the code...
    user.insert(db).await?
}

When I try to create a new user, I get the following error: "Error creating user: UnpackInsertId". I believe this error is related to the UUID primary key. Any help would be greatly appreciated