Compound index for inherited field

Hi, I’m trying to include an inherited field from an inherited class in the subclass’ compound index. E.g.:

from django.db import models

# Create your models here.
class Base(models.Model):
    name = models.CharField(max_length=20, db_index=True)

class Child(Base):
    age = models.IntegerField()

    class Meta:
        indexes = [
                fields = ['name', 'age']

Django complains

python makemigrations
SystemCheckError: System check identified some issues:

demo.Child: (models.E016) 'indexes' refers to field 'name' which is not local to model 'Child'.
	HINT: This issue may be caused by multi-table inheritance.

Is there a way to include an inherited field in a compound index? Thank you so much!

Please post the complete Models involved here, there are a couple different things that could be wrong.

Thanks @KenWhitesell I included the code in the original posting. I’m using Django 3.1.5.

By not specifying abstract=True in the Meta class within the base class, you’re using multi-table inheritance. That means that Base and Child are two separate database tables, each with their own columns and indexes.

See Models | Django documentation | Django for more information.

1 Like

Thank you so much for your answer!!