Skip to content
Discussion options

You must be logged in to vote

I checked it works the same way with Pydantic model. So, it's not an SQLModel's issue.

You can solve this by adding a field_validator to conbert NaT to None:

...

+from pydantic import field_validator

class HeroMeeting(SQLModel):
    id: int | None = Field(primary_key=True, default=None)
    name: str = Field(max_length=255, default=None)
    time: datetime | None = Field(default=None)

+   @field_validator("time", mode="before")
+   @classmethod
+   def nat_to_none(cls, value):
+       if value is pd.NaT:
+           return None
+       return value

...

Replies: 1 comment 1 reply

Comment options

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

Answer selected by YuriiMotov
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