[Fixed]-What's equivalent to Django's auto_now, auto_now_add in SQLAlchemy?

36👍

Finally, after checking the SQLAlchemy doc, this should be the way:

Column('created_on', DateTime, default=datetime.datetime.now)

Column('last_updated', DateTime, onupdate=datetime.datetime.now)

doc here:

http://docs.sqlalchemy.org/en/latest/core/defaults.html#python-executed-functions

0👍

It’s still possible to use the following:

enter_date = Column(DateTime, default=datetime.datetime.utcnow, onupdate=datetime.datetime.utcnow)

On update also sqlalchemy set the current date at the time the data updates.

Leave a comment