Gloria W wrote:
Hi All,
Looking back in these posts, I tried several older variants of MySQL
datetime column initialization discussed here, and they're not
working.
This works in Postgresql:
sqlalchemy.Column('date_created', sqlalchemy.DateTime,
sqlalchemy.PassiveDefault(sqlalchemy.sql.func.now()),
nullable=False)
But the MySQL equivalent fails:
sqlalchemy.Column('date_created', sqlalchemy.DateTime,
sqlalchemy.PassiveDefault(text("CURRENT_TIMESTAMP")),
nullable=False)
What is the valid syntax? Is it failing for other reasons?
The MySQL TIMESTAMP type is required for that default:
from sqlalchemy.databases import mysql
sqlalchemy.Column('date_created', mysql.MSDateTime,
sqlalchemy.PassiveDefault(text("CURRENT_TIMESTAMP")),
nullable=False)