django-phone-field icon indicating copy to clipboard operation
django-phone-field copied to clipboard

[Migrations] `null=True, unique=True` Raises `django.db.utils.IntegrityError: UNIQUE constraint failed` when running migration

Open jjorissen52 opened this issue 4 years ago • 8 comments

To reproduce, make sure some rows already exist for MyModel, then add a PhoneField to it.

class MyModel(models.Model):
    -pass
    +phone = PhoneField(null=True, blank=True, unique=True)
python manage.py makemigrations
python manage.py migrate
# django.db.utils.IntegrityError: UNIQUE constraint failed: new__myapp_mymodel.phone

jjorissen52 avatar Oct 01 '20 17:10 jjorissen52