Search code examples
pythondjangodatetimemodel

Django DateTimeField auto_now_add not working


In one of the model i have set one timestamp field as follows:

created_datetime = models.DateTimeField(auto_now_add = True)

While in shell i am able to create a obj and save it, however in my application it is raising a exception that created_datetime field cannot be null.

Confused where things went wrong!! How to reslove it.


Solution

  • You can do something like this

    created_datetime = models.DateTimeField(auto_now_add=True, auto_now=False)