Skip to content

sea-orm-cli generate entity emits rs_type = "Enum" instead of rs_type = "String" for PostgreSQL native enums #3104

Description

@lethib

Description

When generating entities from a PostgreSQL database that contains native ENUM types, sea-orm-cli generate entity --entity-format dense emits rs_type = "Enum" in the #[sea_orm(...)] attribute of the generated ActiveEnum, instead of rs_type = "String".

Enum is not a valid Rust type, so the generated sea_orm_active_enums.rs does not compile as-is. The correct value (per the documentation) might be rs_type = "String".

Steps to Reproduce

  1. Create a PostgreSQL native enum type and a table using it:
CREATE TYPE payment_method AS ENUM ('card', 'cash', 'check', 'transfer');

CREATE TABLE payments (
    id           serial PRIMARY KEY,
    method       payment_method NOT NULL
);
  1. Generate entities using the dense format:
sea-orm-cli generate entity \
  --database-url postgres://... \
  --with-serde both \
  --entity-format dense \
  --impl-active-model-behavior=false \
  -o ./src/models/_entities/
  1. Open the generated src/models/_entities/sea_orm_active_enums.rs.

Expected Behavior

The generated ActiveEnum uses rs_type = "String":

#[derive(Debug, Clone, PartialEq, Eq, EnumIter, DeriveActiveEnum, Serialize, Deserialize)]
#[sea_orm(rs_type = "String", db_type = "Enum", enum_name = "payment_method")]
pub enum PaymentMethod {
    #[sea_orm(string_value = "card")]
    Card,
    #[sea_orm(string_value = "cash")]
    Cash,
    #[sea_orm(string_value = "check")]
    Check,
    #[sea_orm(string_value = "transfer")]
    Transfer,
}

Actual Behavior

rs_type is generated as "Enum", which is not a valid Rust type and fails to compile:

#[derive(Debug, Clone, PartialEq, Eq, EnumIter, DeriveActiveEnum, Serialize, Deserialize)]
#[sea_orm(rs_type = "Enum", db_type = "Enum", enum_name = "payment_method")]
pub enum PaymentMethod {
    #[sea_orm(string_value = "card")]
    Card,
    // ...
}

Reproduces How Often

Always, on every entity generation, for every PostgreSQL native enum column.

Workarounds

Manually editing rs_type = "Enum" back to rs_type = "String" after each generation produces working, compiling code. Post-processing the generated file (search/replace rs_type = "Enum"rs_type = "String") as part of the generation pipeline works around it automatically.

Versions

sea-bae v0.2.1
sea-orm v2.0.0-rc.41
sea-orm-cli v2.0.0-rc.41
sea-orm-macros v2.0.0-rc.41
sea-orm-migration v2.0.0-rc.41
sea-query v1.0.1
sea-query-derive v1.0.0
sea-query-sqlx v0.9.1
sea-schema v0.18.0
sea-schema-derive v0.3.0
  • Database: PostgreSQL (via sqlx-postgres)
  • OS: macOS 26.5.1 (arm64)
  • --entity-format dense

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions