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 16:55:25 +0100
commite55cb91bd47d054d502c03cdbe74ac98986af3fb (patch)
treec4ede60eeae113ef24b436b0c536640bcaa494cb /django
parent0b3e3e21cfe7463245dc1dfc9258e18903bc1116 (diff)
[1.8.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/base/schema.py24
1 files changed, 12 insertions, 12 deletions
diff --git a/django/db/backends/base/schema.py b/django/db/backends/base/schema.py
index 4a63088d30..467d5fb397 100644
--- a/django/db/backends/base/schema.py
+++ b/django/db/backends/base/schema.py
@@ -488,18 +488,6 @@ class BaseDatabaseSchemaEditor(object):
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:
@@ -513,6 +501,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: