summaryrefslogtreecommitdiff
path: root/django/db/backends/sqlite3
diff options
context:
space:
mode:
authorAndrew Gorcester <andrew.gorcester@gmail.com>2014-04-08 12:30:25 +0700
committerSimon Charette <charette.s@gmail.com>2014-04-18 16:44:47 -0400
commit956bd644249337b9467c017aac4eec228dde8c5d (patch)
tree1178ab5fc81da173e5446a8d659c9b61fef2ad45 /django/db/backends/sqlite3
parent26d118c3fea34d9487a93b8ae570ef90e7079a76 (diff)
Fixed #22397 -- Issues removing M2M field with explicit through model
Changed the migration autodetector to remove models last so that FK and M2M fields will not be left as dangling references. Added a check in the migration state renderer to error out in the presence of dangling references instead of leaving them as strings. Fixed a bug in the sqlite backend to handle the deletion of M2M fields with "through" models properly (i.e., do nothing successfully). Thanks to melinath for report, loic for tests and andrewgodwin and charettes for assistance with architecture.
Diffstat (limited to 'django/db/backends/sqlite3')
-rw-r--r--django/db/backends/sqlite3/schema.py12
1 files changed, 8 insertions, 4 deletions
diff --git a/django/db/backends/sqlite3/schema.py b/django/db/backends/sqlite3/schema.py
index 216ff0958a..a8417d4f66 100644
--- a/django/db/backends/sqlite3/schema.py
+++ b/django/db/backends/sqlite3/schema.py
@@ -121,11 +121,15 @@ class DatabaseSchemaEditor(BaseDatabaseSchemaEditor):
Removes a field from a model. Usually involves deleting a column,
but for M2Ms may involve deleting a table.
"""
- # Special-case implicit M2M tables
- if isinstance(field, ManyToManyField) and field.rel.through._meta.auto_created:
- return self.delete_model(field.rel.through)
+ # M2M fields are a special case
+ if isinstance(field, ManyToManyField):
+ # For implicit M2M tables, delete the auto-created table
+ if field.rel.through._meta.auto_created:
+ self.delete_model(field.rel.through)
+ # For explicit "through" M2M fields, do nothing
# For everything else, remake.
- self._remake_table(model, delete_fields=[field])
+ else:
+ self._remake_table(model, delete_fields=[field])
def alter_field(self, model, old_field, new_field, strict=False):
"""