I am adding a field to an existing model:
...
booking_id = models.CharField(null=False, unique=True, max_length=5)
...
Now when I run ./manage makemigrations, ask for a default value. This value is created in a pre_save signal. What should I give as default value in this case?
Obviously if I give a default value, when I run ./manage migrate this raises django.db.utils.IntegrityError
Add the field with null=True, and create a migration. Then add a data migration to populate the field. Finally, set null=False and create a final migration to add the NOT NULL constraint.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With