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

-3👍

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

3👍

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()

https://docs.djangoproject.com/en/3.1/ref/django-admin/#django-admin-loaddata

Leave a comment