summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorMarkus Holtermann <info@markusholtermann.eu>2015-01-19 15:31:23 +0100
committerMarkus Holtermann <info@markusholtermann.eu>2015-01-19 17:25:05 +0100
commitdb2a97870d74bc689428d9c2a942115ef799f2d2 (patch)
tree52ee6bd7dae79c4d50b72b141d469e6cb82bcb88 /django
parentbb2b4acc7a8435e204b772954995487e87866ef9 (diff)
[1.7.x] Fixed #24163 -- Removed unique constraint after index on MySQL
Thanks Ɓukasz Harasimowicz for the report. Backport of 5792e6a88c1444d4ec84abe62077338ad3765b80 from master
Diffstat (limited to 'django')
-rw-r--r--django/db/backends/schema.py24
1 files changed, 12 insertions, 12 deletions
diff --git a/django/db/backends/schema.py b/django/db/backends/schema.py
index f13bde8bf5..7c10db7dec 100644
--- a/django/db/backends/schema.py
+++ b/django/db/backends/schema.py
@@ -457,18 +457,6 @@ class BaseDatabaseSchemaEditor(object):
def _alter_field(self, model, old_field, new_field, old_type, new_type, old_db_params, new_db_params, strict=False):
"""Actually perform a "physical" (non-ManyToMany) field update."""
- # Has unique been removed?
- if old_field.unique and (not new_field.unique or (not old_field.primary_key and new_field.primary_key)):
- # Find the unique constraint for this field
- constraint_names = self._constraint_names(model, [old_field.column], unique=True)
- if strict and len(constraint_names) != 1:
- raise ValueError("Found wrong number (%s) of unique constraints for %s.%s" % (
- len(constraint_names),
- model._meta.db_table,
- old_field.column,
- ))
- for constraint_name in constraint_names:
- self.execute(self._delete_constraint_sql(self.sql_delete_unique, model, constraint_name))
# Drop any FK constraints, we'll remake them later
fks_dropped = set()
if old_field.rel and old_field.db_constraint:
@@ -482,6 +470,18 @@ class BaseDatabaseSchemaEditor(object):
for fk_name in fk_names:
fks_dropped.add((old_field.column,))
self.execute(self._delete_constraint_sql(self.sql_delete_fk, model, fk_name))
+ # Has unique been removed?
+ if old_field.unique and (not new_field.unique or (not old_field.primary_key and new_field.primary_key)):
+ # Find the unique constraint for this field
+ constraint_names = self._constraint_names(model, [old_field.column], unique=True)
+ if strict and len(constraint_names) != 1:
+ raise ValueError("Found wrong number (%s) of unique constraints for %s.%s" % (
+ len(constraint_names),
+ model._meta.db_table,
+ old_field.column,
+ ))
+ for constraint_name in constraint_names:
+ self.execute(self._delete_constraint_sql(self.sql_delete_unique, model, constraint_name))
# Drop incoming FK constraints if we're a primary key and things are going
# to change.
if old_field.primary_key and new_field.primary_key and old_type != new_type: