agronholm / sqlacodegen

Automatic model code generator for SQLAlchemy
Other
1.86k stars 241 forks source link

Not picking up unsigned number fields properly #347

Open robvdl opened 1 week ago

robvdl commented 1 week ago

Things to check first

Sqlacodegen version

3.0.0rc5

SQLAlchemy version

2.0.34

RDBMS vendor

MySQL (or compatible)

What happened?

I generated models from an existing MySQL database and wherever "unsigned int" was used, sqlacodegen incorrectly translated it to INTEGER rather than INTEGER(unsigned=True).

There was even an unsigned decimal in the source schema that can happen too, that needed to become DECIMAL(3, 9, unsigned=True) for example.

Sorry I can't really release the source schema, customer database.

Database schema for reproducing the bug

No response

agronholm commented 1 week ago

This version of SQLAlchemy is not supported. I suggest you try with SQLAlchemy 2.x.

robvdl commented 1 week ago

Oh somehow I mistyped that, it was meant to be 2.0.34, I'll fix it.

robvdl commented 1 week ago

If I have to create an example, I can probably craft something up over the weekend.

Basically I've found that wherever UNSIGNED is used, sqlacodegen is not picking that part up and just interpreting it as INTEGER rather than INTEGER(unsiged=True). This is using the MySQL specific INTEGER field in SQLAlchemy.

What sqlacodegen seems to have done is it has used the right field type wherever UNSIGNED is used it seems to have picked the MySQL specific field. It's just lacking unsigned=True as the args.

agronholm commented 1 week ago

Is SQLAlchemy's reflection picking up the unsigned? If not, there's nothing I can do.

robvdl commented 6 days ago

Understood. I'lll have to have a look.