Reputation: 417
Say, I have a model with this field:
is_retired = models.NullBooleanField()
It has never been set for any of the records i the database, so I think all the records will have a null value for this field.
And now want to change it to a string field:
is_retired = models.CharField(max_length=50)
I am using Django 1.7 and ran makemigrations
which seemed to go fine, said something about altered field. However, when I actually run the migrate
command it fails with
django.db.utils.IntegrityError: column "is_retired" contains null values
How can I resolve this?
Upvotes: 1
Views: 908
Reputation: 1840
If you want to enable null/empty values, change it to:
is_retired = models.CharField(max_length=50, null=True, blank=True)
You might also want to change the null values to empty strings ('') in another migration.
Upvotes: 3