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


Python migration.Migration方法代码示例

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


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

示例1: apply_operations

# 需要导入模块: from django.db.migrations import migration [as 别名]
# 或者: from django.db.migrations.migration import Migration [as 别名]
def apply_operations(self, app_label, project_state, operations):
        migration = Migration('name', app_label)
        migration.operations = operations
        with connection.schema_editor() as editor:
            return migration.apply(project_state, editor) 
开发者ID:denisenkom,项目名称:django-sqlserver,代码行数:7,代码来源:test_operations.py

示例2: unapply_operations

# 需要导入模块: from django.db.migrations import migration [as 别名]
# 或者: from django.db.migrations.migration import Migration [as 别名]
def unapply_operations(self, app_label, project_state, operations):
        migration = Migration('name', app_label)
        migration.operations = operations
        with connection.schema_editor() as editor:
            return migration.unapply(project_state, editor) 
开发者ID:denisenkom,项目名称:django-sqlserver,代码行数:7,代码来源:test_operations.py

示例3: apply_operations

# 需要导入模块: from django.db.migrations import migration [as 别名]
# 或者: from django.db.migrations.migration import Migration [as 别名]
def apply_operations(self, app_label, project_state, operations, atomic=True):
        migration = Migration('name', app_label)
        migration.operations = operations
        with connection.schema_editor(atomic=atomic) as editor:
            return migration.apply(project_state, editor) 
开发者ID:nesdis,项目名称:djongo,代码行数:7,代码来源:test_operations.py

示例4: unapply_operations

# 需要导入模块: from django.db.migrations import migration [as 别名]
# 或者: from django.db.migrations.migration import Migration [as 别名]
def unapply_operations(self, app_label, project_state, operations, atomic=True):
        migration = Migration('name', app_label)
        migration.operations = operations
        with connection.schema_editor(atomic=atomic) as editor:
            return migration.unapply(project_state, editor) 
开发者ID:nesdis,项目名称:djongo,代码行数:7,代码来源:test_operations.py

示例5: test_run_python_atomic

# 需要导入模块: from django.db.migrations import migration [as 别名]
# 或者: from django.db.migrations.migration import Migration [as 别名]
def test_run_python_atomic(self):
        """
        Tests the RunPython operation correctly handles the "atomic" keyword
        """
        project_state = self.set_up_test_model("test_runpythonatomic", mti_model=True)

        def inner_method(models, schema_editor):
            Pony = models.get_model("test_runpythonatomic", "Pony")
            Pony.objects.create(pink=1, weight=3.55)
            raise ValueError("Adrian hates ponies.")

        atomic_migration = Migration("test", "test_runpythonatomic")
        atomic_migration.operations = [migrations.RunPython(inner_method)]
        non_atomic_migration = Migration("test", "test_runpythonatomic")
        non_atomic_migration.operations = [migrations.RunPython(inner_method, atomic=False)]
        # If we're a fully-transactional database, both versions should rollback
        if connection.features.can_rollback_ddl:
            self.assertEqual(project_state.apps.get_model("test_runpythonatomic", "Pony").objects.count(), 0)
            with self.assertRaises(ValueError):
                with connection.schema_editor() as editor:
                    atomic_migration.apply(project_state, editor)
            self.assertEqual(project_state.apps.get_model("test_runpythonatomic", "Pony").objects.count(), 0)
            with self.assertRaises(ValueError):
                with connection.schema_editor() as editor:
                    non_atomic_migration.apply(project_state, editor)
            self.assertEqual(project_state.apps.get_model("test_runpythonatomic", "Pony").objects.count(), 0)
        # Otherwise, the non-atomic operation should leave a row there
        else:
            self.assertEqual(project_state.apps.get_model("test_runpythonatomic", "Pony").objects.count(), 0)
            with self.assertRaises(ValueError):
                with connection.schema_editor() as editor:
                    atomic_migration.apply(project_state, editor)
            self.assertEqual(project_state.apps.get_model("test_runpythonatomic", "Pony").objects.count(), 0)
            with self.assertRaises(ValueError):
                with connection.schema_editor() as editor:
                    non_atomic_migration.apply(project_state, editor)
            self.assertEqual(project_state.apps.get_model("test_runpythonatomic", "Pony").objects.count(), 1)
        # And deconstruction
        definition = non_atomic_migration.operations[0].deconstruct()
        self.assertEqual(definition[0], "RunPython")
        self.assertEqual(definition[1], [])
        self.assertEqual(sorted(definition[2]), ["atomic", "code"]) 
开发者ID:denisenkom,项目名称:django-sqlserver,代码行数:44,代码来源:test_operations.py


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