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?
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 gotunique = 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 thedb_index = Truebit.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 thenamefields being created withUNIQUE?