-
Notifications
You must be signed in to change notification settings - Fork 130
Closed
Description
When a field is nullable and unique, a filtered index is created to enforce uniqueness instead of a unique constraint.
But when the field is made non-unique and still nullable, the generated SQL uses DROP CONSTRAINT instead of DROP INDEX, which doesn't work.
In our case this happened when changing this model:
class MyModel(models.Model):
field1= models.CharField(max_length=254, null=True, unique=True)
field2 = models.ForeignKey('myapp.othermodel', null=False, on_delete=models.deletion.CASCADE)
To this model:
class MyModel(models.Model):
field1= models.CharField(max_length=254, null=True)
field2 = models.ForeignKey('myapp.othermodel', null=False, on_delete=models.deletion.CASCADE)
class Meta:
unique_together = ('field2', 'field1')
Probably also happens without the unique_together but by just setting unique=False.
Metadata
Metadata
Assignees
Labels
No labels