Search code examples
djangodjango-modelsdjango-fixtures

Is DateTimeField with auto_now_add option enabled must has value in fixtures


I have model created field configurated as follows:

created = models.DateTimeField(auto_now_add=True)

In JSON fixtures I don't want to declare value for created, but when I try to load fixtures (loadata) I am getting error:

created may not be NULL

So I must provide created value in fixtures or there is an other way?


Solution

  • Try

    import datetime
    created = models.DateTimeField(default=datetime.datetime.now)
    

    And about why this happening you can read over here: Django auto_now and auto_now_add and Django model field default