Fixed SeaOrm Rust type `core::option::Option<sqlx_postgres::types::oid::Oid>` (as SQL type `OID`) is not compatible with SQL type `INT8`

tianlang 发布于2025年05月19日03:16

Problem:

A Rust project using SeaORM threw an error during testing.

running 1 test
Error: Query Error: error occurred while decoding column 1: mismatched types; > Rust type core::option::Option<sqlx_postgres::types::oid::Oid> (as > SQL type OID) is not compatible with SQL type INT8

Caused by:
    0: error occurred while decoding column 1: mismatched types; Rust type core::option::Option<sqlx_postgres::types::oid::Oid> (as SQL type OID) is not compatible with SQL type INT8
    1: error occurred while decoding column 1: mismatched types; Rust type core::option::Option<sqlx_postgres::types::oid::Oid> (as SQL type OID) is not compatible with SQL type INT8
    2: mismatched types; Rust type core::option::Option<sqlx_postgres::types::oid::Oid> (as SQL type OID) is not compatible with SQL type INT8
test services::order::tests::test_count_orders_of_jobs_in_last_days ... FAILED

Solution:

I resolved the issue by changing a model's field type from u32 to i32.

#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Deserialize, Serialize, Default)]
#[serde(rename_all = "camelCase")]
#[sea_orm(table_name = "account")]
pub struct Model {
    #[sea_orm(primary_key)]
    #[serde(skip_deserializing)]
    pub id: i32,//updated from u32 to i32
    #[sea_orm(unique)]
    pub name: String,
    pub password: Option<String>,
    #[serde(serialize_with = "serialize_cookie")]
    pub cookie: Option<String>,
    pub first_address_id: Option<String>,
    pub login_status: Option<i16>,
    pub status_check_at: Option<chrono::DateTime<Local>>,
    #[serde(skip_deserializing)]
    pub updated_at: chrono::DateTime<Local>,
}

Root Cause:

The model’s field type in Rust did not match the corresponding database column type.

Additional Note

The error message referencing types::oid::Oid may be confusing. Changing the field type to i16 instead of u32 could provide a clearer error message.