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-17 12:54:35 -0400
commit00e3b9a2a992ee0b7288eeeb03e7cbd52ebc6dce (patch)
tree84c93ed5daf82e14006b2d3b867b13a5edc1357f /django/db/backends/sqlite3
parent47927eb786f432cb069f0b00fd810c465a78fd71 (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):
"""