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.