gpt4 book ai didi

python - 我需要在这个 Django 模型中添加一个 db_index 吗?

转载 作者:IT老高 更新时间:2023-10-28 22:25:16 25 4
gpt4 key购买 nike

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com