How Do You Get Sqlalchemy To Override Mysql "on Update Current_timestamp"
I've inherited an older database that was setup with a 'on update CURRENT_TIMESTAMP' put on a field that should only describe an item's creation. With PHP I have been using 'times
Solution 1:
SQLAlchemy doesn't try to set the field because it thinks the value hasn't changed.
You can tell SQLAlchemy to reassign the value by specifying the onupdate attribute on the Column:
Column('timestamp', ..., onupdate=literal_column('timestamp'))
This will result in SQLAlchemy automatically adding timestamp=timestamp
to all update queries.
If you need to do it one off on an instance, you can assign the column to it:
foo.timestamp = literal_column('timestamp')
# or foo.timestamp = foo_tbl.c.timestamp
Post a Comment for "How Do You Get Sqlalchemy To Override Mysql "on Update Current_timestamp""