使用SQLAlchemy、alembic和postgres时,当试图将列设置为行创建时间时,我最终得到的是一个默认为表本身创建时间而不是行创建时间的字段。
模型代码:
Alembic将其翻译为:
模型代码:
datetime = sa.Column(sa.DateTime, nullable=False, server_default=func.now())
Alembic将其翻译为:
sa.Column('datetime', sa.DateTime(), server_default='now()', nullable=False),
以及在Postgres中的列:
datetime | timestamp without time zone | not null default '2013-06-24 11:28:14.930524'::timestamp without time zone
我该怎么做才能使默认时间为行创建时间?
server_default=func.now
而不是server_default=func.now()
,而不是提交一个正确的答案? - Doobehdefault=datetime.now
来描述我的时间戳列。我找到了(并测试了)一种使用server_default
的解决方案,我将其作为答案留下。 - Doobeh