Non-automatic conversion of variables using sea-orm


I am facing a strange problem.

I already have a database created and now I want to move the architecture to rust. For the ORM, I started to write the fields, but I have a problem with the enums part.

My enum in the db is "DeviceType" but rust automatically converts my "devicetype" and I have the following error when saving in the database

#[derive(EnumIter, DeriveActiveEnum, Debug, PartialEq, Eq, Clone, Deserialize)]
#[sea_orm(rs_type = "String", db_type = "Enum", enum_name = "DeviceType")]
pub enum DeviceType {
    #[sea_orm(string_value = "DESKTOP_WINDOWS")]
    #[sea_orm(string_value = "DESKTOP_MACOS")]
    #[sea_orm(string_value = "IOS")]
    #[sea_orm(string_value = "ANDROID")]
TODO: panic message: Query(SqlxError(Database(PgDatabaseError { severity: Error, code: "42704", message: "type \"devicetype\" does not exist", detail: None, hint: None, position: Some(Original(118)), where: None, schema: None, table: None, column: None, data_type: None, constraint: None, file: Some("parse_type.c"), line: Some(270), routine: Some("typenameType") })))
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Some ideas?

1 Like

Had the exact same issue, turns out after looking at the sql query that the type casting did look ok


but for some reason postgres still doesn't like it.

The way I solved it was by adding escaped double quotes around my enum_name, like so:

enum_name = "\"TitleCaseEnum\""

Which resulted in the following sql, that postgres likes a lot better

CAST('SOME_VALUE' AS "TitleCaseEnum")