当前位置: 首页>>代码示例>>Python>>正文


Python migrations.AlterUniqueTogether方法代码示例

本文整理汇总了Python中django.db.migrations.AlterUniqueTogether方法的典型用法代码示例。如果您正苦于以下问题:Python migrations.AlterUniqueTogether方法的具体用法?Python migrations.AlterUniqueTogether怎么用?Python migrations.AlterUniqueTogether使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在django.db.migrations的用法示例。


在下文中一共展示了migrations.AlterUniqueTogether方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _test_create_alter_foo_delete_model

# 需要导入模块: from django.db import migrations [as 别名]
# 或者: from django.db.migrations import AlterUniqueTogether [as 别名]
def _test_create_alter_foo_delete_model(self, alter_foo):
        """
        CreateModel, AlterModelTable, AlterUniqueTogether/AlterIndexTogether/
        AlterOrderWithRespectTo, and DeleteModel should collapse into nothing.
        """
        self.assertOptimizesTo(
            [
                migrations.CreateModel("Foo", [("name", models.CharField(max_length=255))]),
                migrations.AlterModelTable("Foo", "woohoo"),
                alter_foo,
                migrations.DeleteModel("Foo"),
            ],
            [],
        ) 
开发者ID:denisenkom,项目名称:django-sqlserver,代码行数:16,代码来源:test_optimizer.py

示例2: test_create_alter_unique_delete_model

# 需要导入模块: from django.db import migrations [as 别名]
# 或者: from django.db.migrations import AlterUniqueTogether [as 别名]
def test_create_alter_unique_delete_model(self):
        self._test_create_alter_foo_delete_model(migrations.AlterUniqueTogether("Foo", [["a", "b"]])) 
开发者ID:denisenkom,项目名称:django-sqlserver,代码行数:4,代码来源:test_optimizer.py

示例3: _test_alter_alter_model

# 需要导入模块: from django.db import migrations [as 别名]
# 或者: from django.db.migrations import AlterUniqueTogether [as 别名]
def _test_alter_alter_model(self, alter_foo, alter_bar):
        """
        Two AlterUniqueTogether/AlterIndexTogether/AlterOrderWithRespectTo
        should collapse into the second.
        """
        self.assertOptimizesTo(
            [
                alter_foo,
                alter_bar,
            ],
            [
                alter_bar,
            ],
        ) 
开发者ID:denisenkom,项目名称:django-sqlserver,代码行数:16,代码来源:test_optimizer.py

示例4: test_alter_alter_unique_model

# 需要导入模块: from django.db import migrations [as 别名]
# 或者: from django.db.migrations import AlterUniqueTogether [as 别名]
def test_alter_alter_unique_model(self):
        self._test_alter_alter_model(
            migrations.AlterUniqueTogether("Foo", [["a", "b"]]),
            migrations.AlterUniqueTogether("Foo", [["a", "c"]]),
        ) 
开发者ID:denisenkom,项目名称:django-sqlserver,代码行数:7,代码来源:test_optimizer.py

示例5: test_create_alter_unique_field

# 需要导入模块: from django.db import migrations [as 别名]
# 或者: from django.db.migrations import AlterUniqueTogether [as 别名]
def test_create_alter_unique_field(self):
        self._test_create_alter_foo_field(migrations.AlterUniqueTogether("Foo", [["a", "b"]])) 
开发者ID:denisenkom,项目名称:django-sqlserver,代码行数:4,代码来源:test_optimizer.py

示例6: test_alter_unique_together

# 需要导入模块: from django.db import migrations [as 别名]
# 或者: from django.db.migrations import AlterUniqueTogether [as 别名]
def test_alter_unique_together(self):
        """
        Tests the AlterUniqueTogether operation.
        """
        project_state = self.set_up_test_model("test_alunto")
        # Test the state alteration
        operation = migrations.AlterUniqueTogether("Pony", [("pink", "weight")])
        self.assertEqual(operation.describe(), "Alter unique_together for Pony (1 constraint(s))")
        new_state = project_state.clone()
        operation.state_forwards("test_alunto", new_state)
        self.assertEqual(len(project_state.models["test_alunto", "pony"].options.get("unique_together", set())), 0)
        self.assertEqual(len(new_state.models["test_alunto", "pony"].options.get("unique_together", set())), 1)
        # Make sure we can insert duplicate rows
        with connection.cursor() as cursor:
            cursor.execute("INSERT INTO test_alunto_pony (pink, weight) VALUES (1, 1)")
            cursor.execute("INSERT INTO test_alunto_pony (pink, weight) VALUES (1, 1)")
            cursor.execute("DELETE FROM test_alunto_pony")
            # Test the database alteration
            with connection.schema_editor() as editor:
                operation.database_forwards("test_alunto", editor, project_state, new_state)
            cursor.execute("INSERT INTO test_alunto_pony (pink, weight) VALUES (1, 1)")
            with self.assertRaises(IntegrityError):
                with atomic():
                    cursor.execute("INSERT INTO test_alunto_pony (pink, weight) VALUES (1, 1)")
            cursor.execute("DELETE FROM test_alunto_pony")
            # And test reversal
            with connection.schema_editor() as editor:
                operation.database_backwards("test_alunto", editor, new_state, project_state)
            cursor.execute("INSERT INTO test_alunto_pony (pink, weight) VALUES (1, 1)")
            cursor.execute("INSERT INTO test_alunto_pony (pink, weight) VALUES (1, 1)")
            cursor.execute("DELETE FROM test_alunto_pony")
        # Test flat unique_together
        operation = migrations.AlterUniqueTogether("Pony", ("pink", "weight"))
        operation.state_forwards("test_alunto", new_state)
        self.assertEqual(len(new_state.models["test_alunto", "pony"].options.get("unique_together", set())), 1)
        # And deconstruction
        definition = operation.deconstruct()
        self.assertEqual(definition[0], "AlterUniqueTogether")
        self.assertEqual(definition[1], [])
        self.assertEqual(definition[2], {'name': "Pony", 'unique_together': {("pink", "weight")}}) 
开发者ID:denisenkom,项目名称:django-sqlserver,代码行数:42,代码来源:test_operations.py

示例7: test_alter_unique_together_remove

# 需要导入模块: from django.db import migrations [as 别名]
# 或者: from django.db.migrations import AlterUniqueTogether [as 别名]
def test_alter_unique_together_remove(self):
        operation = migrations.AlterUniqueTogether("Pony", None)
        self.assertEqual(operation.describe(), "Alter unique_together for Pony (0 constraint(s))") 
开发者ID:denisenkom,项目名称:django-sqlserver,代码行数:5,代码来源:test_operations.py

示例8: test_create_model_with_unique_after

# 需要导入模块: from django.db import migrations [as 别名]
# 或者: from django.db.migrations import AlterUniqueTogether [as 别名]
def test_create_model_with_unique_after(self):
        """
        Tests the CreateModel operation directly followed by an
        AlterUniqueTogether (bug #22844 - sqlite remake issues)
        """
        operation1 = migrations.CreateModel(
            "Pony",
            [
                ("id", models.AutoField(primary_key=True)),
                ("pink", models.IntegerField(default=1)),
            ],
        )
        operation2 = migrations.CreateModel(
            "Rider",
            [
                ("id", models.AutoField(primary_key=True)),
                ("number", models.IntegerField(default=1)),
                ("pony", models.ForeignKey("test_crmoua.Pony", models.CASCADE)),
            ],
        )
        operation3 = migrations.AlterUniqueTogether(
            "Rider",
            [
                ("number", "pony"),
            ],
        )
        # Test the database alteration
        project_state = ProjectState()
        self.assertTableNotExists("test_crmoua_pony")
        self.assertTableNotExists("test_crmoua_rider")
        with connection.schema_editor() as editor:
            new_state = project_state.clone()
            operation1.state_forwards("test_crmoua", new_state)
            operation1.database_forwards("test_crmoua", editor, project_state, new_state)
            project_state, new_state = new_state, new_state.clone()
            operation2.state_forwards("test_crmoua", new_state)
            operation2.database_forwards("test_crmoua", editor, project_state, new_state)
            project_state, new_state = new_state, new_state.clone()
            operation3.state_forwards("test_crmoua", new_state)
            operation3.database_forwards("test_crmoua", editor, project_state, new_state)
        self.assertTableExists("test_crmoua_pony")
        self.assertTableExists("test_crmoua_rider") 
开发者ID:nesdis,项目名称:djongo,代码行数:44,代码来源:test_operations.py


注:本文中的django.db.migrations.AlterUniqueTogether方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。