#32393: Indexes of only the first abstract base class are included in the model
-----------------------------------------+------------------------
               Reporter:  Dmitry Ulupov  |          Owner:  nobody
                   Type:  Bug            |         Status:  new
              Component:  Migrations     |        Version:  3.1
               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              |
-----------------------------------------+------------------------
 If model has multiple base abstract models, their {{{ Meta.indexes }}}
 declarations are treated differently.

 Only indexes from the first class are taken into account.
 Indexes of all other base classes are ignored.

 Consider this code:

 {{{
 class ParentA(models.Model):
     field_a = models.CharField(max_length=10)

     class Meta:
         abstract = True


 class ParentB(models.Model):
     field_b = models.CharField(max_length=10)

     class Meta:
         abstract = True
         indexes = [
             models.Index(
                 fields=["field_b"],
                 name="ix_%(app_label)s_%(class)s",
             ),
         ]


 class ChildOf_A_B(ParentA, ParentB):
     pass


 class ChildOf_B_A(ParentB, ParentA):
     pass

 }}}

 makemigrations in this case produces this:

 {{{

 ./manage.py makemigrations app

 Migrations for 'app':
   project/app/migrations/0001_initial.py
     - Create model ChildOf_A_B
     - Create model ChildOf_B_A
     - Create index ix_app_childof_b_a on field(s) field_b of model
 childof_b_a

 }}}

 So index on ChildOf_B_A is created, but on ChildOf_A_B is not.
 And only difference is the order of declaration of the base classes.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/32393>
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/053.2a49b906dc0fdce27d1ff9561bb4cc37%40djangoproject.com.

Reply via email to