我只是想保持安全。我有这个型号:
class Player(models.Model):
name = models.CharField(max_length=64, db_index=True)
...
class Match(models.Model):
date = models.DateField()
playerA = models.ForeignKey(Player, related_name='playerA') # neither here db_index
playerB = models.ForeignKey(Player, related_name='playerB') # nor here db_index
...
db_index
的使用是否正确?而且,无需为playerA
或playerB
添加额外的索引?
答案 0 :(得分:1)
Django自动为所有models.ForeignKey列创建索引。只需运行“./manage.py sql appname”,您就会看到用于创建索引的sql语句。