You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If we add a models.ForeignKey from table foo to table bar, the Django automatically sets up an index on the new field on table foo, not using CONCURRENTLY. This means if we introduce a ForeignKey field, Postgres will hold a full AccessExclusiveLock at least on the referencing table foo while the index is built.
This is problematic especially if the foreign key field is added to large tables (even though the newly added field contains no data), making the full transaction slow, and especially if the referenced table is accessed a lot.
Example model file:
# Inside model Foofield_name=models.ForeignKey(
"Bar",
related_name="from_field_name",
blank=True,
null=True,
on_delete=models.PROTECT,
)
If we add a
models.ForeignKey
from tablefoo
to tablebar
, the Django automatically sets up an index on the new field on tablefoo
, not usingCONCURRENTLY
. This means if we introduce aForeignKey
field, Postgres will hold a fullAccessExclusiveLock
at least on the referencing tablefoo
while the index is built.This is problematic especially if the foreign key field is added to large tables (even though the newly added field contains no data), making the full transaction slow, and especially if the referenced table is accessed a lot.
Example model file:
Example migration file:
The text was updated successfully, but these errors were encountered: