diff options
| author | Chris Beaven <smileychris@gmail.com> | 2014-03-18 16:54:35 +1300 |
|---|---|---|
| committer | Chris Beaven <smileychris@gmail.com> | 2014-03-18 16:54:35 +1300 |
| commit | b47ef04ea2a3b1a48160253dd0ab906e621cecee (patch) | |
| tree | 9b69d631c8ae4b3bccfbb80f0ea25fae6ae26bb7 /django/db/backends/sqlite3/schema.py | |
| parent | cc5804bcab9e410a2c0fc2225fd0233bf8db0511 (diff) | |
Fix any sqlite field migration deleting all implicit m2m tables
Fixes #22281
Diffstat (limited to 'django/db/backends/sqlite3/schema.py')
| -rw-r--r-- | django/db/backends/sqlite3/schema.py | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/django/db/backends/sqlite3/schema.py b/django/db/backends/sqlite3/schema.py index e8fc2635d1..8c6db9776a 100644 --- a/django/db/backends/sqlite3/schema.py +++ b/django/db/backends/sqlite3/schema.py @@ -64,6 +64,9 @@ class DatabaseSchemaEditor(BaseDatabaseSchemaEditor): for field in delete_fields: del body[field.name] del mapping[field.column] + # Remove any implicit M2M tables + if isinstance(field, ManyToManyField) and field.rel.through._meta.auto_created: + return self.delete_model(field.rel.through) # Work inside a new app registry apps = Apps() # Construct a new model for the new state @@ -87,8 +90,11 @@ class DatabaseSchemaEditor(BaseDatabaseSchemaEditor): ', '.join(self.quote_name(y) for x, y in field_maps), self.quote_name(model._meta.db_table), )) - # Delete the old table - self.delete_model(model) + # Delete the old table (not using self.delete_model to avoid deleting + # all implicit M2M tables) + self.execute(self.sql_delete_table % { + "table": self.quote_name(model._meta.db_table), + }) # Rename the new to the old self.alter_db_table(model, temp_model._meta.db_table, model._meta.db_table) # Run deferred SQL on correct table |
