SeaQL / sea-orm

🐚 An async & dynamic ORM for Rust
https://www.sea-ql.org/SeaORM/
Apache License 2.0
6.94k stars 483 forks source link

orm-cli generated incorrect type for #[sea_orm(primary_key)]. Should be u64. Was i64. #295

Closed exzachlyvv closed 2 years ago

exzachlyvv commented 2 years ago

It appears that orm-cli failed to handle unsigned type as a primary key when generating models.

This later resulted in a:

panicked at 'Failed to fetch user.: Query("error occurred while decoding column \"id\": mismatched types; Rust type `core::option::Option<i64>` (as SQL type `BIGINT`) is not compatible with SQL type `BIGINT UNSIGNED`")'
billy1624 commented 2 years ago

Hi @exzachlyvv, are you using MySQL?

exzachlyvv commented 2 years ago

Yep, MySQL

billy1624 commented 2 years ago

Currently, we did not capture UNSIGNED flag inside sea-schema so sea-orm-codegen fail to annotate the column as u64.

I guess unsigned integer types are not included in sea-query because not all database drivers support it? @tyt2y3 https://github.com/SeaQL/sea-query/blob/e05a85196fdba9b838b4fb5b62970c783d9c604d/src/table/column.rs#L12-L39

tyt2y3 commented 2 years ago

Yes, you are right. I checked, SeaSchema did parse unsigned types.

col_type: SmallInt(
    NumericAttr {
        maximum: None,
        decimal: None,
        unsigned: Some(
            true,
        ),
        zero_fill: None,
    },
)

But yeah we have to add it to SeaQuery first before it could be supported. The implication is though, it will not be portable as Postgres does not support unsigned.