Skip to content

Commit

Permalink
Fixed #23013 -- Fixed removing unique_together/index_together constra…
Browse files Browse the repository at this point in the history
…ints in migrations.

Thanks melinath for the report.
  • Loading branch information
timgraham committed Jul 15, 2014
1 parent b65a200 commit 0154965
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
4 changes: 2 additions & 2 deletions django/db/migrations/operations/models.py
Expand Up @@ -248,7 +248,7 @@ def references_model(self, name, app_label=None):
return name.lower() == self.name.lower() return name.lower() == self.name.lower()


def describe(self): def describe(self):
return "Alter %s for %s (%s constraint(s))" % (self.option_name, self.name, len(self.unique_together)) return "Alter %s for %s (%s constraint(s))" % (self.option_name, self.name, len(self.unique_together or ''))




class AlterIndexTogether(Operation): class AlterIndexTogether(Operation):
Expand Down Expand Up @@ -288,7 +288,7 @@ def references_model(self, name, app_label=None):
return name.lower() == self.name.lower() return name.lower() == self.name.lower()


def describe(self): def describe(self):
return "Alter %s for %s (%s constraint(s))" % (self.option_name, self.name, len(self.index_together)) return "Alter %s for %s (%s constraint(s))" % (self.option_name, self.name, len(self.index_together or ''))




class AlterOrderWithRespectTo(Operation): class AlterOrderWithRespectTo(Operation):
Expand Down
2 changes: 0 additions & 2 deletions django/db/migrations/state.py
Expand Up @@ -272,8 +272,6 @@ def render(self, apps):
# First, make a Meta object # First, make a Meta object
meta_contents = {'app_label': self.app_label, "apps": apps} meta_contents = {'app_label': self.app_label, "apps": apps}
meta_contents.update(self.options) meta_contents.update(self.options)
if "unique_together" in meta_contents:
meta_contents["unique_together"] = list(meta_contents["unique_together"])
meta = type(str("Meta"), tuple(), meta_contents) meta = type(str("Meta"), tuple(), meta_contents)
# Then, work out our bases # Then, work out our bases
try: try:
Expand Down
8 changes: 8 additions & 0 deletions tests/migrations/test_operations.py
Expand Up @@ -899,6 +899,10 @@ def test_alter_unique_together(self):
operation.state_forwards("test_alunto", new_state) operation.state_forwards("test_alunto", new_state)
self.assertEqual(len(new_state.models["test_alunto", "pony"].options.get("unique_together", set())), 1) self.assertEqual(len(new_state.models["test_alunto", "pony"].options.get("unique_together", set())), 1)


def test_alter_unique_together_remove(self):
operation = migrations.AlterUniqueTogether("Pony", None)
self.assertEqual(operation.describe(), "Alter unique_together for Pony (0 constraint(s))")

def test_alter_index_together(self): def test_alter_index_together(self):
""" """
Tests the AlterIndexTogether operation. Tests the AlterIndexTogether operation.
Expand All @@ -922,6 +926,10 @@ def test_alter_index_together(self):
operation.database_backwards("test_alinto", editor, new_state, project_state) operation.database_backwards("test_alinto", editor, new_state, project_state)
self.assertIndexNotExists("test_alinto_pony", ["pink", "weight"]) self.assertIndexNotExists("test_alinto_pony", ["pink", "weight"])


def test_alter_index_together_remove(self):
operation = migrations.AlterIndexTogether("Pony", None)
self.assertEqual(operation.describe(), "Alter index_together for Pony (0 constraint(s))")

def test_alter_model_options(self): def test_alter_model_options(self):
""" """
Tests the AlterModelOptions operation. Tests the AlterModelOptions operation.
Expand Down

0 comments on commit 0154965

Please sign in to comment.