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

标签 python mysql database django indexing

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/

相关文章:

mysql - 如何在MYSQL 中的连续id 范围内找到已删除的id?

python - Python 中的 URL 错误

python - 检查 Django 模板中的请求获取参数

python - 在 numpy 中快速找到对称对

php - 如何加快查询速度?

mysql - 当 mysql(innoDB) 表被更改(锁定)时,插入会发生什么?

python - 为什么 pandas.DataFrame.sum(axis=0) 返回每列中的值的总和,其中轴 =0 表示行?

mysql - #2014 在 phpMyAdmin 上运行查询时的同步命令

java - 员工数据库程序的 ArrayIndexOutOfBounds 异常

database - 将远程 PHP 服务与 Flex (Flash Builder) AIR 应用程序结合使用?