First Check
Commit to Help
Example Code
importenumimportuuidfromsqlalchemyimportEnum, Column, create_mock_enginefromsqlalchemy.sql.type_apiimportTypeEnginefromsqlmodelimportSQLModel, FieldclassMyEnum(enum.Enum):
A='A'B='B'classMyEnum2(enum.Enum):
C='C'D='D'classBaseModel(SQLModel):
id: uuid.UUID=Field(primary_key=True)
enum_field: MyEnum2=Field(sa_column=Column(Enum(MyEnum2)))
classFlatModel(SQLModel, table=True):
id: uuid.UUID=Field(primary_key=True)
enum_field: MyEnum=Field(sa_column=Column(Enum(MyEnum)))
classInheritModel(BaseModel, table=True):
passdefdump(sql: TypeEngine, *args, **kwargs):
dialect=sql.compile(dialect=engine.dialect)
sql_str=str(dialect).rstrip()
ifsql_str:
print(sql_str+';')
engine=create_mock_engine('postgresql://', dump)
SQLModel.metadata.create_all(bind=engine, checkfirst=False)Description
When executing the above example code, the output shows that only the enum from FlatModel is correctly created, while the enum from the inherited class is not:
CREATETYPEmyenumAS ENUM ('A', 'B');
# There should be a TYPE def for myenum2, but isn'tCREATETABLEflatmodel (
enum_field myenum, id UUID NOT NULL, PRIMARY KEY (id)
);
CREATEINDEXix_flatmodel_idON flatmodel (id);
CREATETABLEinheritmodel (
enum_field myenum2, id UUID NOT NULL, PRIMARY KEY (id)
);
CREATEINDEXix_inheritmodel_idON inheritmodel (id);Operating System
macOS
Operating System Details
No response
SQLModel Version
0.0.4
Python Version
3.9.7
Additional Context
No response
First Check
Commit to Help
Example Code
Description
When executing the above example code, the output shows that only the enum from FlatModel is correctly created, while the enum from the inherited class is not:
Operating System
macOS
Operating System Details
No response
SQLModel Version
0.0.4
Python Version
3.9.7
Additional Context
No response