美文网首页
Django 索引

Django 索引

作者: 早起早起早起up | 来源:发表于2019-10-17 10:08 被阅读0次

应该索引的字段

1.需要排序操作的字段   (order_by)

2.需要比较操作的字段  (> < >=, <=)

3.需要过滤操作的字段   (filter   exclude)

索引添加

属性中定义

模型的Meta 属性类  nickname = models.CharField(max_length=256,db_index=True)

class Meta:

indexes=[

models.Index(fields=['nickname']),

]

在meta  加组合索引   

class Meta:

indexes=[

models.Index(fields=['nickname','open_ids']),

]

索引规则

1.主键必定是索引

2.外键默认是索引

相关文章

网友评论

      本文标题:Django 索引

      本文链接:https://www.haomeiwen.com/subject/uecmmctx.html