Skip to content

Commit 93d3756

Browse files
author
Christian Hattemer
committed
Allow to use Enums in custom DB schema
1 parent 059970f commit 93d3756

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
@@ -645,6 +645,12 @@ def __init__(
645645
ModelMetaclass.__init__(cls, classname, bases, dict_, **kw)
646646

647647

648+
class SchemaEnum(sa_Enum):
649+
def __init__(self, *args, **kwargs):
650+
kwargs['inherit_schema'] = True
651+
super().__init__(*args, **kwargs)
652+
653+
648654
def get_sqlalchemy_type(field: Any) -> Any:
649655
if IS_PYDANTIC_V2:
650656
field_info = field
@@ -659,7 +665,7 @@ def get_sqlalchemy_type(field: Any) -> Any:
659665

660666
# Check enums first as an enum can also be a str, needed by Pydantic/FastAPI
661667
if issubclass(type_, Enum):
662-
return sa_Enum(type_)
668+
return SchemaEnum(type_)
663669
if issubclass(
664670
type_,
665671
(

0 commit comments

Comments
 (0)