Skip to content

Commit e37df31

Browse files
author
Christian Hattemer
committed
Allow to use Enums in custom DB schema
1 parent e7744e5 commit e37df31

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

sqlmodel/main.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -643,6 +643,12 @@ def __init__(
643643
ModelMetaclass.__init__(cls, classname, bases, dict_, **kw)
644644

645645

646+
class SchemaEnum(sa_Enum):
647+
def __init__(self, *args: Any, **kwargs: Any) -> None:
648+
kwargs["inherit_schema"] = True
649+
super().__init__(*args, **kwargs)
650+
651+
646652
def get_sqlalchemy_type(field: Any) -> Any:
647653
if IS_PYDANTIC_V2:
648654
field_info = field
@@ -657,7 +663,7 @@ def get_sqlalchemy_type(field: Any) -> Any:
657663

658664
# Check enums first as an enum can also be a str, needed by Pydantic/FastAPI
659665
if issubclass(type_, Enum):
660-
return sa_Enum(type_)
666+
return SchemaEnum(type_)
661667
if issubclass(
662668
type_,
663669
(

0 commit comments

Comments
 (0)