Skip to content

SQLModel cannot fetch the type of a enum field containing Annotated type #903

Discussion options

You must be logged in to vote

In fact this error comes from sqlalchemy, you can see that the error disapeear if you remove the tablle=True

So what you can do is specify a sa_type to make sqlalchemy understand what type you actually want to be used in the database side.

Something like that should fix your problem:

from sqlalchemy import DateTime  # if you want the DateTime type or String if you want it to be a string

class Product(BaseModel, table=True):
    created: ISOTimestamp = Field(default_factory=utc_now, nullable=False, sa_type=DateTime)
    deprecated: ISOTimestamp | None = Field(default=None, sa_type=DateTime)

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@fubuloubu
Comment options

Answer selected by fubuloubu
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
2 participants