當我插入一行時,該字段被填滿了服務器啓動的時間,而不是該行插入的時間。爲什麼會發生這種情況,解決方案是什麼?順便說一句,我正在使用SQLite。在Peewee我有一個日期時間字段默認datetime.datetime.now()。但插入時,服務器啓動需要花費時間。爲什麼
class LOG(peewee.Model):
id = peewee.IntegerField(unique=True,primary_key=True)
timestamp = peewee.DateTimeField(default=datetime.datetime.now())
log = peewee.CharField()
by = peewee.IntegerField(default=1)
class Meta:
database = database
LOG.create(log = _log , by = _by)
# above statement is called at say 3:00 pm and I started the server at 2:00 pm, then the row is inserted with timestamp of 2pm not 3pm.
這是不完全正確。 Peewee支持可調參數,所以你可以說'default = datetime.datetime.now'(沒有括號)。 – coleifer