1

Currently, I have 3 models, A, B and C

C has foreign key to B B has foreign key to A

class C(models.Model):
    name = models.CharField(max_length=50, db_index=True, unique=True)
    b = models.ForeignKey(B)
class B:
...similar to C
class A
...similar to C except for the FK

However, the SQL generated by manage.py sqlindexes app doesn't create indexes for C.name, B.name, and A.name. Anyone know why this happens?

1 Answer 1

1

That looks to me like it'll be because the fields also have unique = True, so I wouldn't worry too much about it. If you've got unique = True, then you'll get a unique index (which may or may not be implemented as a database index), so I guess Django just ignores the db_index = True bit.

I get very similar behaviour for one of my models that is similarly specified. What output do you get when run manage.py sql app? Do you see the name fields being created with UNIQUE?

Sign up to request clarification or add additional context in comments.

1 Comment

Hmm I just ran sqlindexes on the app again and it generated indexes for name. Donno what happened in the OP lol

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.