Skip to content
Advertisement

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.

Advertisement

Answer

You can do something like this

created_datetime = models.DateTimeField(auto_now_add=True, auto_now=False)
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement