當前位置: 首頁>>代碼示例>>Python>>正文


Python migrations.RemoveIndex方法代碼示例

本文整理匯總了Python中django.db.migrations.RemoveIndex方法的典型用法代碼示例。如果您正苦於以下問題:Python migrations.RemoveIndex方法的具體用法?Python migrations.RemoveIndex怎麽用?Python migrations.RemoveIndex使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在django.db.migrations的用法示例。


在下文中一共展示了migrations.RemoveIndex方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_indexes_ignore_swapped

# 需要導入模塊: from django.db import migrations [as 別名]
# 或者: from django.db.migrations import RemoveIndex [as 別名]
def test_indexes_ignore_swapped(self):
        """
        Add/RemoveIndex operations ignore swapped models.
        """
        operation = migrations.AddIndex('Pony', models.Index(fields=['pink'], name='my_name_idx'))
        project_state, new_state = self.make_test_state('test_adinigsw', operation)
        with connection.schema_editor() as editor:
            # No database queries should be run for swapped models
            operation.database_forwards('test_adinigsw', editor, project_state, new_state)
            operation.database_backwards('test_adinigsw', editor, new_state, project_state)

        operation = migrations.RemoveIndex('Pony', models.Index(fields=['pink'], name='my_name_idx'))
        project_state, new_state = self.make_test_state("test_rminigsw", operation)
        with connection.schema_editor() as editor:
            operation.database_forwards('test_rminigsw', editor, project_state, new_state)
            operation.database_backwards('test_rminigsw', editor, new_state, project_state) 
開發者ID:denisenkom,項目名稱:django-sqlserver,代碼行數:18,代碼來源:test_operations.py

示例2: test_remove_index_state_forwards

# 需要導入模塊: from django.db import migrations [as 別名]
# 或者: from django.db.migrations import RemoveIndex [as 別名]
def test_remove_index_state_forwards(self):
        project_state = self.set_up_test_model('test_rminsf')
        index = models.Index(fields=['pink'], name='test_rminsf_pony_pink_idx')
        migrations.AddIndex('Pony', index).state_forwards('test_rminsf', project_state)
        old_model = project_state.apps.get_model('test_rminsf', 'Pony')
        new_state = project_state.clone()

        operation = migrations.RemoveIndex('Pony', 'test_rminsf_pony_pink_idx')
        operation.state_forwards('test_rminsf', new_state)
        new_model = new_state.apps.get_model('test_rminsf', 'Pony')
        self.assertIsNot(old_model, new_model) 
開發者ID:denisenkom,項目名稱:django-sqlserver,代碼行數:13,代碼來源:test_operations.py

示例3: test_remove_index

# 需要導入模塊: from django.db import migrations [as 別名]
# 或者: from django.db.migrations import RemoveIndex [as 別名]
def test_remove_index(self):
        """
        Test the RemoveIndex operation.
        """
        project_state = self.set_up_test_model("test_rmin", multicol_index=True)
        self.assertTableExists("test_rmin_pony")
        self.assertIndexExists("test_rmin_pony", ["pink", "weight"])
        operation = migrations.RemoveIndex("Pony", "pony_test_idx")
        self.assertEqual(operation.describe(), "Remove index pony_test_idx from Pony")
        new_state = project_state.clone()
        operation.state_forwards("test_rmin", new_state)
        # Test the state alteration
        self.assertEqual(len(new_state.models["test_rmin", "pony"].options['indexes']), 0)
        self.assertIndexExists("test_rmin_pony", ["pink", "weight"])
        # Test the database alteration
        with connection.schema_editor() as editor:
            operation.database_forwards("test_rmin", editor, project_state, new_state)
        self.assertIndexNotExists("test_rmin_pony", ["pink", "weight"])
        # And test reversal
        with connection.schema_editor() as editor:
            operation.database_backwards("test_rmin", editor, new_state, project_state)
        self.assertIndexExists("test_rmin_pony", ["pink", "weight"])
        # And deconstruction
        definition = operation.deconstruct()
        self.assertEqual(definition[0], "RemoveIndex")
        self.assertEqual(definition[1], [])
        self.assertEqual(definition[2], {'model_name': "Pony", 'name': "pony_test_idx"})

        # Also test a field dropped with index - sqlite remake issue
        operations = [
            migrations.RemoveIndex("Pony", "pony_test_idx"),
            migrations.RemoveField("Pony", "pink"),
        ]
        self.assertColumnExists("test_rmin_pony", "pink")
        self.assertIndexExists("test_rmin_pony", ["pink", "weight"])
        # Test database alteration
        new_state = project_state.clone()
        self.apply_operations('test_rmin', new_state, operations=operations)
        self.assertColumnNotExists("test_rmin_pony", "pink")
        self.assertIndexNotExists("test_rmin_pony", ["pink", "weight"])
        # And test reversal
        self.unapply_operations("test_rmin", project_state, operations=operations)
        self.assertIndexExists("test_rmin_pony", ["pink", "weight"]) 
開發者ID:denisenkom,項目名稱:django-sqlserver,代碼行數:45,代碼來源:test_operations.py


注:本文中的django.db.migrations.RemoveIndex方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。