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 typecore::option::Option<sqlx_postgres::types::oid::Oid>
(as > SQL typeOID
) is not compatible with SQL typeINT8
Caused by:
0: error occurred while decoding column 1: mismatched types; Rust typecore::option::Option<sqlx_postgres::types::oid::Oid>
(as SQL typeOID
) is not compatible with SQL typeINT8
1: error occurred while decoding column 1: mismatched types; Rust typecore::option::Option<sqlx_postgres::types::oid::Oid>
(as SQL typeOID
) is not compatible with SQL typeINT8
2: mismatched types; Rust typecore::option::Option<sqlx_postgres::types::oid::Oid>
(as SQL typeOID
) is not compatible with SQL typeINT8
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.