(str, Enum)
fields are no longer (automatically) treated as strings in SQL
#717
Replies: 3 comments
-
Could there maybe be a generic solution for overriding the default mappings from python types to sql? BTW we were using postgres string enums, and maybe it's a good default, but I figure not using them is a valid usecase too. |
Beta Was this translation helpful? Give feedback.
-
This change in the handling of Enums is a breaking change for existing schemas that previously used the VARCHAR field to store python Enums. The previous values (the python Enum values) aren't compatible with the new database Enum values (derived from the python Enum names). This forces projects to add additional migration steps to map the existing values or modify code to use the Would love to see a simple (and supported) way to change default mappings |
Beta Was this translation helpful? Give feedback.
-
Just got nailed by this on an upgrade branch (brought about by other dependencies forcing pydantic v2). Any resolution or tips/tricks in the past 10 months? |
Beta Was this translation helpful? Give feedback.
-
First Check
Commit to Help
Example Code
Description
Prior to
0.0.9
, all of mystr, Enum
types were utilizingAutoString
and stored as varchars in postgres. Since #669, these types are now converted to postgres Enum fields, which is not desirable for my use case.A very hacky workaround I found is to monkeypatch
sa_Enum
in thesqlmodel.main
module, which works since I am not using sqlalchemy.Enum fields anywhere:I know another solution is to override every enum field with a
sqlmodel.Field(sa_column=...)
, but I'd prefer a global solution to treat all(str, Enum)
types asAutoString
instead ofsqlalchemy.Enum
.Operating System
Linux
Operating System Details
No response
SQLModel Version
0.0.12
Python Version
3.11.5
Additional Context
No response
Beta Was this translation helpful? Give feedback.
All reactions