Column default value persisted to the table

后端 未结 2 1332
不思量自难忘°
不思量自难忘° 2021-02-15 16:58

I am currently using a Column that has the following signature:

Column(\'my_column\', DateTime, default=datetime.datetime.utcnow)

I am

2条回答
  •  南旧
    南旧 (楼主)
    2021-02-15 17:04

    If you wanted to insert UTC time you would have to do something like this:

    from sqlalchemy import text
    ...
    created = Column(DateTime,
                     server_default=text("(now() at time zone 'utc')"),
                     nullable=False)
    

提交回复
热议问题