Django 是否自动为外键列生成索引?

Django 是自动为外键生成索引,还是仅仅依赖于底层 DB 策略?

28321 次浏览

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 setting db_index to False. 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.