當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。