mercredi 7 octobre 2015

In Peewee I have a datetime field defaulted to datetime.datetime.now(). But when inserted, it takes the time the server was started. Why

When I insert a row, the field is filled with the time when the server was started not the time when the row was inserted. Why is this happening and what is the solution? BTW I am using SQLite.

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.

Aucun commentaire:

Enregistrer un commentaire