Ticket #23013: 23013.diff

File 23013.diff, 3.0 KB (added by Tim Graham, 10 years ago)

Still need to add a test for changes to state.py

  • django/db/migrations/operations/models.py

    diff --git a/django/db/migrations/operations/models.py b/django/db/migrations/operations/models.py
    index 1c2f209..1ded7c6 100644
    a b class AlterUniqueTogether(Operation):  
    248248        return name.lower() == self.name.lower()
    249249
    250250    def describe(self):
    251         return "Alter %s for %s (%s constraint(s))" % (self.option_name, self.name, len(self.unique_together))
     251        return "Alter %s for %s (%s constraint(s))" % (self.option_name, self.name, len(self.unique_together or ''))
    252252
    253253
    254254class AlterIndexTogether(Operation):
    class AlterIndexTogether(Operation):  
    288288        return name.lower() == self.name.lower()
    289289
    290290    def describe(self):
    291         return "Alter %s for %s (%s constraint(s))" % (self.option_name, self.name, len(self.index_together))
     291        return "Alter %s for %s (%s constraint(s))" % (self.option_name, self.name, len(self.index_together or ''))
    292292
    293293
    294294class AlterOrderWithRespectTo(Operation):
  • django/db/migrations/state.py

    diff --git a/django/db/migrations/state.py b/django/db/migrations/state.py
    index ab1c39f..c26153a 100644
    a b class ModelState(object):  
    273273        meta_contents = {'app_label': self.app_label, "apps": apps}
    274274        meta_contents.update(self.options)
    275275        if "unique_together" in meta_contents:
    276             meta_contents["unique_together"] = list(meta_contents["unique_together"])
     276            meta_contents["unique_together"] = list(meta_contents["unique_together"]) if meta_contents["unique_together"] is not None else None
    277277        meta = type(str("Meta"), tuple(), meta_contents)
    278278        # Then, work out our bases
    279279        try:
  • tests/migrations/test_operations.py

    diff --git a/tests/migrations/test_operations.py b/tests/migrations/test_operations.py
    index 5444dae..b8d1ae5 100644
    a b class OperationTests(OperationTestBase):  
    899899        operation.state_forwards("test_alunto", new_state)
    900900        self.assertEqual(len(new_state.models["test_alunto", "pony"].options.get("unique_together", set())), 1)
    901901
     902    def test_alter_unique_together_remove(self):
     903        operation = migrations.AlterUniqueTogether("Pony", None)
     904        self.assertEqual(operation.describe(), "Alter unique_together for Pony (0 constraint(s))")
     905
    902906    def test_alter_index_together(self):
    903907        """
    904908        Tests the AlterIndexTogether operation.
    class OperationTests(OperationTestBase):  
    922926            operation.database_backwards("test_alinto", editor, new_state, project_state)
    923927        self.assertIndexNotExists("test_alinto_pony", ["pink", "weight"])
    924928
     929    def test_alter_index_together_remove(self):
     930        operation = migrations.AlterIndexTogether("Pony", None)
     931        self.assertEqual(operation.describe(), "Alter index_together for Pony (0 constraint(s))")
     932
    925933    def test_alter_model_options(self):
    926934        """
    927935        Tests the AlterModelOptions operation.
Back to Top