Does Django automatically generate indexes for foreign keys columns?

后端 未结 1 498
再見小時候
再見小時候 2021-01-30 19:52

Does Django automatically generate indexes for foreign keys, or does it just depend on the underlying DB policy ?

1条回答
  •  醉梦人生
    2021-01-30 20:21

    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.

    0 讨论(0)
提交回复
热议问题