In SQLAlchemy, how do I create a 'MySQL date' column? In SQLAlchemy, how do I create a 'MySQL date' column? database database

In SQLAlchemy, how do I create a 'MySQL date' column?


You can provide default and onupdate parameters to Column:

def _get_date():    return datetime.datetime.now()class Posts(Base):    #...    created_at = Column(Date, default=_get_date)    updated_at = Column(Date, onupdate=_get_date)

See Column documentation for more info on this one.