[Fixed]-Is DateTimeField with auto_now_add option enabled must has value in fixtures



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


You can use pre_save signal to process loaddata(fixtures)

@receiver(pre_save, sender=MyModel)
def pre_save_for_conference_code_fixture(sender, instance, **kwargs):
  if kwargs['raw']:
    instance.updated_at = timezone.now()
      if not instance.id:
        instance.created_at = timezone.now()


Leave a comment