summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Charette <charette.s@gmail.com>2020-04-07 01:02:55 -0400
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2020-04-20 13:13:57 +0200
commit330c0ed7c4cf915c1a9982d94bce01fe3c9e9f1e (patch)
treefeb9d257e9adbc0e2025c5b2a52d479df8409499
parent505fec6badba0622bbf97bb659188c3d62a9bc58 (diff)
Stopped rebuilding referenced tables multiple times on SQLite alterations.
-rw-r--r--django/db/backends/sqlite3/schema.py12
1 files changed, 9 insertions, 3 deletions
diff --git a/django/db/backends/sqlite3/schema.py b/django/db/backends/sqlite3/schema.py
index a4885c5632..d1b113f1b9 100644
--- a/django/db/backends/sqlite3/schema.py
+++ b/django/db/backends/sqlite3/schema.py
@@ -360,9 +360,15 @@ class DatabaseSchemaEditor(BaseDatabaseSchemaEditor):
self._remake_table(model, alter_field=(old_field, new_field))
# Rebuild tables with FKs pointing to this field if the PK type changed.
if old_field.primary_key and new_field.primary_key and old_type != new_type:
- for rel in new_field.model._meta.related_objects:
- if not rel.many_to_many:
- self._remake_table(rel.related_model)
+ related_models = set()
+ for remote_field in new_field.model._meta.related_objects:
+ # Ignore self-relationship since the table was already rebuilt.
+ if remote_field.related_model == model:
+ continue
+ if not remote_field.many_to_many:
+ related_models.add(remote_field.related_model)
+ for related_model in related_models:
+ self._remake_table(related_model)
def _alter_many_to_many(self, model, old_field, new_field, strict):
"""Alter M2Ms to repoint their to= endpoints."""