SqlAlchemy won't accept datetime.datetime.now value in a DateTime column

自作多情 提交于 2019-12-04 23:45:20

Try to use datetime.datetime.utcnow(). This works for me.

last_updated = db.Column(db.DateTime, default=db.func.current_timestamp())

I think this will work

Set the import out the class.

from datetime import datetime

last_updated = db.Column(db.DateTime, default=datetime.now())

or

import datetime

last_updated = db.Column(db.DateTime, default=datetime.datetime.now())

I did this

Look at your line:

last_updated = db.Column(db.DateTime, default=datetime.datetime.now)

There is no datetime.datetime.now attribute in python. However, there is a datetime.datetime.now() function in python. You were just missing a pair of parentheses.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!