尽管使用 DateTimeField(default=datetime.datetime.now) ,但无法设置默认时间戳 该列设置为非空,但未设置默认值
我有我的模型
import datetime
database = PostgresqlDatabase(dbname,username,password,host)
class BaseModel(Model):
class Meta:
database = database
class UserInfo(BaseModel):
id = PrimaryKeyField()
username = CharField(unique=True)
password = CharField()
email = CharField(null=True)
created_date = DateTimeField(default=datetime.datetime.now)
当我使用这个模型和下面的代码创建表时
database.connect()
database.create_tables([UserInfo])
我在桌子下面
Table "public.userinfo" Column | Type | Modifiers --------------+-----------------------------+------------------------- ------------------------------ id | integer | not null default nextval('userinfo_id_seq'::regclass) username | character varying(255) | not null password | character varying(255) | not null email | character varying(255) | created_date | timestamp without time zone | not null Indexes: "userinfo_pkey" PRIMARY KEY, btree (id) "userinfo_username" UNIQUE, btree (username)
在表中创建日期未设置为任何默认值