#33392: Removing or composed indexes fails on MySQL
-----------------------------------------+------------------------
               Reporter:  Sergey Fursov  |          Owner:  nobody
                   Type:  Bug            |         Status:  new
              Component:  Migrations     |        Version:  4.0
               Severity:  Normal         |       Keywords:
           Triage Stage:  Unreviewed     |      Has patch:  0
    Needs documentation:  0              |    Needs tests:  0
Patch needs improvement:  0              |  Easy pickings:  0
                  UI/UX:  0              |
-----------------------------------------+------------------------
 Removing composed indexes that are being created using UniqueConstraint or
 Index added to Meta.contraints/Meta.indexes respectively fails on MySQL
 due to implicit optimization made by MySQL with omitting indexes for a
 foreign key that were initially included in the index.

 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.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/049.23c76a30d8e7f989b662eea9ebe0af2e%40djangoproject.com.

Reply via email to