SeaORM: Enum on with DerivePrimaryKey and DeriveEntityModel Error

SeaORM error on Composite Primary Key Enum with #[derive(DerivePrimaryKey)] in a model with #[derive(DeriveEntityModel)] errors:

error[E0599]: no variant or associated item named `Google` found for enum `user_idp::Column` in the current scope
  --> workspace/entity/src/user_idp.rs:10:5
   |
10 |     Google,
   |     ^^^^^^ variant or associated item not found in `Column`
...
13 | #[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)]
   |                                   ----------------- variant or associated item `Google` not found for this enum

The fix: Remove the DerivePrimaryKey on the enum.

Here’s the patch:

#[derive(Debug, Clone, Copy, PartialEq, Eq, EnumIter, DeriveActiveEnum, DerivePrimaryKey, Serialize, Deserialize)]
//                                                                      ^^^^^^^^^^^^^^^^
#[sea_orm(rs_type = "String", db_type = "Enum", enum_name = "provider")]
pub enum Provider {
    #[sea_orm(string_value = "google")]
    Google,
}

#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)]
#[sea_orm(table_name = "user_idp")]
pub struct Model {
    #[sea_orm(primary_key, auto_increment = false)]
    pub user_id: String,

    #[sea_orm(primary_key, auto_increment = false)]
    pub provider: Provider,

    #[sea_orm(column_type = "Text")]
    pub uid: String,

    pub created_at: DateTimeUtc,

    pub updated_at: DateTimeUtc,
}

Disclaimer:

Not all articles here are meant to be correct. My notes might be wrong or may no longer be relevant. If you want to try things here, please proceed with caution.


Posted

in

by

Tags: