Skip to content

Commit 45e843c

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

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

Diff for: sqlmodel/main.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -645,6 +645,11 @@ def __init__(
645645
ModelMetaclass.__init__(cls, classname, bases, dict_, **kw)
646646

647647

648+
class SchemaEnum(sa_Enum):
649+
def __init__(self, *args, **kwargs):
650+
super().__init__(*args, inherit_schema=True, **kwargs)
651+
652+
648653
def get_sqlalchemy_type(field: Any) -> Any:
649654
if IS_PYDANTIC_V2:
650655
field_info = field
@@ -659,7 +664,7 @@ def get_sqlalchemy_type(field: Any) -> Any:
659664

660665
# Check enums first as an enum can also be a str, needed by Pydantic/FastAPI
661666
if issubclass(type_, Enum):
662-
return sa_Enum(type_)
667+
return SchemaEnum(type_)
663668
if issubclass(
664669
type_,
665670
(

0 commit comments

Comments
 (0)