1
0
mirror of https://github.com/django/django.git synced 2024-12-22 17:16:24 +00:00

Stopped rebuilding referenced tables multiple times on SQLite alterations.

This commit is contained in:
Simon Charette 2020-04-07 01:02:55 -04:00 committed by Mariusz Felisiak
parent 505fec6bad
commit 330c0ed7c4

View File

@ -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."""