coleifer / peewee

a small, expressive orm -- supports postgresql, mysql, sqlite and cockroachdb
http://docs.peewee-orm.com/
MIT License
11.05k stars 1.37k forks source link

Column default value wont (keep) update #34

Closed coderbuzz closed 12 years ago

coderbuzz commented 12 years ago

Hi, I have the following model which have a datetime field with default value=datetime.now()

from datetime import datetime

class ATable(BaseModel):
    time = DateTimeField(default=datetime.now())
    customer = CharField()

Surprised when I create several records say:

ATable.create(customer='A')
# some delay
ATable.create(customer='B')
# some delay
ATable.create(customer='C')

The time (default) filled values was all the same: 2011-12-28 21:30:38.257 on all records The time beeween record creation surelly in different time, at least microsecond and or second value

Perhaps a caching issue?

Thanks

coderbuzz commented 12 years ago

Dooh my mistake, should be:

time = DateTimeField(default=datetime.now)

In previous I pass the now() value, not passing function as arg.

Sorry to pollute