开发者

Do I need to add a db_index to this Django model?

开发者 https://www.devze.com 2023-02-07 04:04 出处:网络
class Comments(models.Model): content = models.ForeignKey(Content) Do I need to add a db_index to \"co开发者_Go百科ntent\"? Or would that automatically be indexed because it\'s a foreign key?Unless
class Comments(models.Model):
    content = models.ForeignKey(Content)

Do I need to add a db_index to "co开发者_Go百科ntent"? Or would that automatically be indexed because it's a foreign key?


Unless specified otherwise, an index will be created for a ForeignKey. Relevant source code:

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
0

精彩评论

暂无评论...
验证码 换一张
取 消