Reputation: 10256
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
Upvotes: 3
Views: 2312
Reputation: 308789
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.
Upvotes: 7