class Comments(models.Model):
content = models.ForeignKey(Content)
我需要将 db_index 添加到“内容”吗?还是会因为它是外键而自动编入索引?
最佳答案
除非另有说明,否则将为 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
关于python - 我需要在这个 Django 模型中添加一个 db_index 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4836327/