views:

223

answers:

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  A: 

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?

Dominic Rodger
No the generated sql do not define name as being unique.
jameszhao00
Hmm I just ran sqlindexes on the app again and it generated indexes for name. Donno what happened in the OP lol
jameszhao00