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


Python migrations.AlterModelTable方法代码示例

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


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

示例1: test_alter_model_table_noop

# 需要导入模块: from django.db import migrations [as 别名]
# 或者: from django.db.migrations import AlterModelTable [as 别名]
def test_alter_model_table_noop(self):
        """
        Tests the AlterModelTable operation if the table name is not changed.
        """
        project_state = self.set_up_test_model("test_almota")
        # Test the state alteration
        operation = migrations.AlterModelTable("Pony", "test_almota_pony")
        new_state = project_state.clone()
        operation.state_forwards("test_almota", new_state)
        self.assertEqual(new_state.models["test_almota", "pony"].options["db_table"], "test_almota_pony")
        # Test the database alteration
        self.assertTableExists("test_almota_pony")
        with connection.schema_editor() as editor:
            operation.database_forwards("test_almota", editor, project_state, new_state)
        self.assertTableExists("test_almota_pony")
        # And test reversal
        with connection.schema_editor() as editor:
            operation.database_backwards("test_almota", editor, new_state, project_state)
        self.assertTableExists("test_almota_pony") 
开发者ID:denisenkom,项目名称:django-sqlserver,代码行数:21,代码来源:test_operations.py

示例2: _test_create_alter_foo_delete_model

# 需要导入模块: from django.db import migrations [as 别名]
# 或者: from django.db.migrations import AlterModelTable [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

示例3: test_alter_alter_table_model

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

示例4: test_alter_model_table

# 需要导入模块: from django.db import migrations [as 别名]
# 或者: from django.db.migrations import AlterModelTable [as 别名]
def test_alter_model_table(self):
        """
        Tests the AlterModelTable operation.
        """
        project_state = self.set_up_test_model("test_almota")
        # Test the state alteration
        operation = migrations.AlterModelTable("Pony", "test_almota_pony_2")
        self.assertEqual(operation.describe(), "Rename table for Pony to test_almota_pony_2")
        new_state = project_state.clone()
        operation.state_forwards("test_almota", new_state)
        self.assertEqual(new_state.models["test_almota", "pony"].options["db_table"], "test_almota_pony_2")
        # Test the database alteration
        self.assertTableExists("test_almota_pony")
        self.assertTableNotExists("test_almota_pony_2")
        with connection.schema_editor() as editor:
            operation.database_forwards("test_almota", editor, project_state, new_state)
        self.assertTableNotExists("test_almota_pony")
        self.assertTableExists("test_almota_pony_2")
        # And test reversal
        with connection.schema_editor() as editor:
            operation.database_backwards("test_almota", editor, new_state, project_state)
        self.assertTableExists("test_almota_pony")
        self.assertTableNotExists("test_almota_pony_2")
        # And deconstruction
        definition = operation.deconstruct()
        self.assertEqual(definition[0], "AlterModelTable")
        self.assertEqual(definition[1], [])
        self.assertEqual(definition[2], {'name': "Pony", 'table': "test_almota_pony_2"}) 
开发者ID:denisenkom,项目名称:django-sqlserver,代码行数:30,代码来源:test_operations.py

示例5: test_alter_model_table_none

# 需要导入模块: from django.db import migrations [as 别名]
# 或者: from django.db.migrations import AlterModelTable [as 别名]
def test_alter_model_table_none(self):
        """
        Tests the AlterModelTable operation if the table name is set to None.
        """
        operation = migrations.AlterModelTable("Pony", None)
        self.assertEqual(operation.describe(), "Rename table for Pony to (default)") 
开发者ID:denisenkom,项目名称:django-sqlserver,代码行数:8,代码来源:test_operations.py

示例6: alter_db_table

# 需要导入模块: from django.db import migrations [as 别名]
# 或者: from django.db.migrations import AlterModelTable [as 别名]
def alter_db_table(field, filters: List[str]):
    """Creates a model with the specified field and then renames the database
    table.

    Arguments:
        field:
            The field to include into the
            model.

        filters:
            List of strings to filter
            SQL statements on.
    """

    model = define_fake_model()
    state = migrations.state.ProjectState.from_apps(apps)

    apply_migration(
        [
            migrations.CreateModel(
                model.__name__, fields=[("title", field.clone())]
            )
        ],
        state,
    )

    with filtered_schema_editor(*filters) as calls:
        apply_migration(
            [migrations.AlterModelTable(model.__name__, "NewTableName")], state
        )

    yield calls 
开发者ID:SectorLabs,项目名称:django-postgres-extra,代码行数:34,代码来源:migrations.py


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