peewee 字段默认类型和 DateTimeField

peewee field default type and DateTimeField

我已经创建了模型 class 继承形式 peewee.Model

import peewee

class Example(peewee.Model):
    id = peewee.IntField(primary_key=True)
    text = peewee.charField(default="waiting")
    dt = peewee.DateTimeField(default=datetime.datetime.now().strftime('%Y-%m-%d'))

但是当我仅将 id 字段的新值插入到 example table 时,我没有得到默认的 text 值作为 "waiting" 和 date_added 也变成了 0000-00-00 00:00:00 isstead of current date time.

字段必须是 class:

的成员
class Example(peewee.Model):
    id = peewee.IntField(primary_key=True)
    text = peewee.charField(default="waiting")
    dt = peewee.DateTimeField(default=datetime.datetime.now)

此外,您希望默认值是日期时间的可调用值...否则它将在加载模块时评估 datetime.datetime.now() 并且永远不会重新评估它。