class Comments(models.Model):
content = models.ForeignKey(Content)
我是否需要在“内容”中添加db_index?或者是否会自动编入索引,因为它是外键?
答案 0 :(得分:43)
除非另有说明,否则将为ForeignKey
创建索引。相关源代码:
class ForeignKey(RelatedField, Field):
# snip
def __init__(self, to, to_field=None, rel_class=ManyToOneRel, **kwargs):
# snip
if 'db_index' not in kwargs:
kwargs['db_index'] = True