The bug might be considered as a regression for the previously fixed
#24757
The initial state of example models
{{{
from django.db import models
class ModelA(models.Model):
pass
class ModelB(models.Model):
a = models.ForeignKey(MyModelA)
b = models.IntegerField()
class Meta:
constraints = models.UniqueConstraint(fields=['a', 'b'],
name='modelb_uniq')
indexes = models.Index(fields=['a', 'b'], name='modelb_index')
}}}
the final state:
{{{
from django.db import models
class ModelA(models.Model):
pass
class ModelB(models.Model):
a = models.ForeignKey(MyModelA)
b = models.IntegerField()
}}}
considering the example states of the models above, MySQL first optimizes
schema by omitting index for ModelB.a FK field as it is already included
in composed index, and then during removing the constraint or the index
migration fails with
{{{
Cannot drop index 'modelb_uniq': needed in a foreign key constraint"
}}}
or
{{{
Cannot drop index 'modelb_index': needed in a foreign key constraint"
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/33392>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
Ticket URL: <https://code.djangoproject.com/ticket/33392#comment:1>
* status: new => closed
* resolution: => duplicate
Comment:
Thanks! IMO we can close this as a duplicate of #31335 (see Simon's
[https://code.djangoproject.com/ticket/31335#comment:2 comment]).
--
Ticket URL: <https://code.djangoproject.com/ticket/33392#comment:2>