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.
Comment (by Dmitry Ulupov):
Just finished re-reading the "multiple inheritance" section and this is an
expected behaviour.
First class indeed clobbers all others and indexes declaration is lost.
Solution is not to have such convoluted structure as I have.
--
Ticket URL: <https://code.djangoproject.com/ticket/32393#comment:1>
* status: new => closed
* resolution: => invalid
--
Ticket URL: <https://code.djangoproject.com/ticket/32393#comment:2>