Issue with created_at timestamp field not being correctly created in schema with default_factory. How do i add timestamp as a column in table in SQLmodel ? #1295
Unanswered
srikrishnasajjarao
asked this question in
Questions
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
First Check
Commit to Help
Example Code
Description
Problem
When defining a model with a
created_at
field usingField(default_factory=datetime.utcnow)
in SQLModel, thecreated_at
field is not being created as a timestamp column in the database schema.Steps to Reproduce
created_at
field usingField(default_factory=datetime.utcnow)
.SQLModel.metadata.create_all(engine)
.created_at
.created_at
field is not correctly set in the database schema.Expected Behavior
The
created_at
field should be automatically created as a timestamp column in the database, and when a new record is created, the field should be populated with the current UTC timestamp.Environment
Additional Information
It seems like the field is not automatically treated as a timestamp column in the database when using
default_factory=datetime.utcnow
. This issue should be addressed to ensure the field is correctly handled both in the model and the database schema.Possible Fix
One solution could be to add support for automatic timestamp handling at the database level or update the documentation for users to handle this behavior manually.
Operating System
Windows
Operating System Details
No response
SQLModel Version
0.0.22
Python Version
3.10.16
Additional Context
No response
Beta Was this translation helpful? Give feedback.
All reactions