Ticket #28861: 28861.diff
File 28861.diff, 3.4 KB (added by , 7 years ago) |
---|
-
tests/schema/models.py
diff --git a/tests/schema/models.py b/tests/schema/models.py index 4512d8b..8490c80 100644
a b 1 1 from django.apps.registry import Apps 2 from django.db import models2 from django.db import connection, models 3 3 4 4 # Because we want to test creation and deletion of these as separate things, 5 5 # these models are all inserted into a separate Apps so the main test … … class BookForeignObj(models.Model): 121 121 apps = new_apps 122 122 123 123 124 if connection.vendor == 'postgresql': 125 from django.contrib.postgres.fields import CICharField 126 127 class CIBookModel(models.Model): 128 title = CICharField(max_length=100, db_index=True) 129 130 class Meta: 131 apps = new_apps 132 133 124 134 class IntegerPK(models.Model): 125 135 i = models.IntegerField(primary_key=True) 126 136 j = models.IntegerField(unique=True) -
tests/schema/tests.py
diff --git a/tests/schema/tests.py b/tests/schema/tests.py index 66a54b1..7c1d010 100644
a b import datetime 2 2 import itertools 3 3 import unittest 4 4 from copy import copy 5 from unittest import mock 5 from unittest import mock, skipUnless 6 6 7 7 from django.db import ( 8 8 DatabaseError, IntegrityError, OperationalError, connection, 9 9 ) 10 from django.db.migrations import Migration 11 from django.db.migrations.state import ProjectState 10 12 from django.db.models import Model 11 13 from django.db.models.deletion import CASCADE, PROTECT 12 14 from django.db.models.fields import ( … … from django.db.transaction import TransactionManagementError, atomic 22 24 from django.test import ( 23 25 TransactionTestCase, skipIfDBFeature, skipUnlessDBFeature, 24 26 ) 25 from django.test.utils import CaptureQueriesContext, isolate_apps 27 from django.test.utils import ( 28 CaptureQueriesContext, isolate_apps, modify_settings, 29 ) 26 30 from django.utils import timezone 27 31 28 32 from .fields import ( … … class SchemaTests(TransactionTestCase): 248 252 editor.alter_field(AuthorCharFieldWithIndex, old_field, new_field, strict=True) 249 253 self.assertForeignKeyExists(AuthorCharFieldWithIndex, 'char_field_id', 'schema_author') 250 254 255 @skipUnless(connection.vendor == 'postgresql', 'PostgreSQL specific tests for citext') 256 @modify_settings(INSTALLED_APPS={'append': 'django.contrib.postgres'}) 257 def test_cichar_field_with_db_index_to_fk(self): 258 from django.contrib.postgres.operations import CITextExtension 259 from .models import CIBookModel 260 self.models.append(CIBookModel) 261 # Create the table and the necessary citext extension 262 migration = Migration('name', app_label='apps') 263 migration.operations = [CITextExtension()] 264 with connection.schema_editor() as editor: 265 editor.create_model(Book) 266 editor.create_model(Author) 267 migration.apply(ProjectState(), editor) 268 editor.create_model(CIBookModel) 269 # Change CICharField to FK 270 old_field = CIBookModel._meta.get_field('title') 271 new_field = ForeignKey(Book, CASCADE, blank=True) 272 new_field.set_attributes_from_name('title') 273 with connection.schema_editor() as editor: 274 editor.alter_field(CIBookModel, old_field, new_field, strict=True) 275 self.assertForeignKeyExists(CIBookModel, 'title_id', 'schema_book') 276 251 277 @skipUnlessDBFeature('supports_foreign_keys') 252 278 @skipUnlessDBFeature('supports_index_on_text_field') 253 279 def test_text_field_with_db_index_to_fk(self):