G
G
German Jet2015-08-21 11:02:53
Django
German Jet, 2015-08-21 11:02:53

Why doesn't auto_now_add work on a Django model?

There are two models:

class Weather(models.Model):
    putdate = models.DateTimeField(auto_now_add=True)
    ...

and
class WeatherCurrent(models.Model):
    putdate = models.DateTimeField(auto_now_add=True)
    ...

New data is added to the first table, auto_now_add=True works there.
In the second table, the existing data is updated, and here, with auto_now_add=True, the table gets 0000-00-00. If you directly insert datetime.today(), then it's fine.
What could be the problem?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir @, 2015-08-21
@GeraJet

auto_now_add is adding the current date when inserting a record into the table, with all subsequent updates of the record, this date will not change. If you want the field to be updated every time the record changes, you need to set the auto_now=True flag

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question