diff options
| author | Motiejus Jakštys <motiejus.jakstys@spilgames.com> | 2014-04-16 16:55:34 +0200 |
|---|---|---|
| committer | Simon Charette <charette.s@gmail.com> | 2014-04-16 16:37:08 -0400 |
| commit | 71c8ae543ffec847ec275859bc406202f5029604 (patch) | |
| tree | 1412b92763258c223ccd31fd0e52a5ec9637863e /django | |
| parent | fcbcdf72d60ccfd808187c3322457decc927712c (diff) | |
[1.7.x] Fixed #22460 -- Explicity remove constraints when dropping a related field.
Backport of 0e45669fa9 from master
Diffstat (limited to 'django')
| -rw-r--r-- | django/db/backends/schema.py | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/django/db/backends/schema.py b/django/db/backends/schema.py index d5bb08e12c..63b0725e22 100644 --- a/django/db/backends/schema.py +++ b/django/db/backends/schema.py @@ -442,8 +442,16 @@ class BaseDatabaseSchemaEditor(object): # It might not actually have a column behind it if field.db_parameters(connection=self.connection)['type'] is None: return - # Get the column's definition - definition, params = self.column_sql(model, field) + # Drop any FK constraints, MySQL requires explicit deletion + if field.rel: + fk_names = self._constraint_names(model, [field.column], foreign_key=True) + for fk_name in fk_names: + self.execute( + self.sql_delete_fk % { + "table": self.quote_name(model._meta.db_table), + "name": fk_name, + } + ) # Delete the column sql = self.sql_delete_column % { "table": self.quote_name(model._meta.db_table), |
