Django会自动为外键列生成索引吗? [英] Does Django automatically generate indexes for foreign keys columns?
问题描述
Django自动为所有 models.ForeignKey
列创建一个索引。
从 Django文档:
在
ForeignKey
上自动创建数据库索引。您可以通过将db_index
设置为False
来禁用此功能。如果您正在创建一个外键以实现一致性而不是连接,或者您将创建一个替代索引(如部分或多个列索引),则可能希望避免索引的开销。
Does Django automatically generate indexes for foreign keys, or does it just depend on the underlying DB policy ?
Django automatically creates an index for all models.ForeignKey
columns.
From Django documentation:
A database index is automatically created on the
ForeignKey
. You can disable this by settingdb_index
toFalse
. You may want to avoid the overhead of an index if you are creating a foreign key for consistency rather than joins, or if you will be creating an alternative index like a partial or multiple column index.
这篇关于Django会自动为外键列生成索引吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!