You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I used the GitHub search to find a similar issue and didn't find it.
I searched the SQLModel documentation, with the integrated search.
I already searched in Google "How to X in SQLModel" and didn't find any information.
I already read and followed all the tutorial in the docs and didn't find an answer.
I already checked if it is not related to SQLModel but to Pydantic.
I already checked if it is not related to SQLModel but to SQLAlchemy.
Commit to Help
I commit to help with one of those options 👆
Example Code
classUserBase(SQLModel):
username: str=Field(index=True, unique=True)
email: EmailStr=Field(unique=True, index=True) # this field should be unique for table and this field is requiredfullname: str|None=Nonecreated_at: datetime=Field(default_factory=datetime.utcnow)
updated_at: datetime=Field(default_factory=datetime.utcnow)
Description
I write my created_at and updated_at fields like this, however, this did not work, because of the time awareness,
It is written with mixing SQLModel stuff and the SALAlchemy, I know SQLModel is SQLAlchemy under the hood but this feels strange, cause i want to face SQLModel ONLY.
Is there any better way of handling this?
Let's say when SQLModel create tables, it will check the payding field created_at, if it is timezone aware datetime then it will set it as sa_column=sa.Column(sa.DateTime(timezone=True) so that we do not need to mix them both,
Operating System
macOS
Operating System Details
No response
SQLModel Version
0.0.8
Python Version
3.10.2
Additional Context
No response
The text was updated successfully, but these errors were encountered:
azataiot
changed the title
Isn't there any better way to write timezone aware datetime field without using the SQLAlchemy ?
Dose there any better way to write timezone aware datetime field without using the SQLAlchemy ?
Jan 26, 2023
Coming from Tortoise ORM moving to SQLModel it would be great to have if the timezone would be saved without having to use SQLAlchemy directly. The project is new so I hope updates could be made soon.
First Check
Commit to Help
Example Code
Description
I write my
created_at
andupdated_at
fields like this, however, this did not work, because of the time awareness,After checking Github, i found this solution:
It is written with mixing SQLModel stuff and the SALAlchemy, I know SQLModel is SQLAlchemy under the hood but this feels strange, cause i want to face SQLModel ONLY.
Is there any better way of handling this?
Let's say when SQLModel create tables, it will check the payding field
created_at
, if it is timezone aware datetime then it will set it assa_column=sa.Column(sa.DateTime(timezone=True)
so that we do not need to mix them both,Operating System
macOS
Operating System Details
No response
SQLModel Version
0.0.8
Python Version
3.10.2
Additional Context
No response
The text was updated successfully, but these errors were encountered: