1
0
mirror of https://github.com/django/django.git synced 2025-10-24 14:16:09 +00:00

Fixed #35469 -- Removed deferred SQL to create index removed by AlterField operation.

This commit is contained in:
Jacob Walls
2024-05-25 17:17:15 -04:00
committed by Sarah Boyce
parent d3a7ed5bcc
commit 99f23eaabd
4 changed files with 70 additions and 9 deletions

View File

@@ -3,7 +3,7 @@ from unittest import skipUnless
from django.conf import settings
from django.db import connection
from django.db.models import CASCADE, ForeignKey, Index, Q
from django.db.models import CASCADE, CharField, ForeignKey, Index, Q
from django.db.models.functions import Lower
from django.test import (
TestCase,
@@ -87,6 +87,24 @@ class SchemaIndexesTests(TestCase):
str(index.create_sql(Article, editor)),
)
@skipUnlessDBFeature("can_create_inline_fk", "can_rollback_ddl")
def test_alter_field_unique_false_removes_deferred_sql(self):
field_added = CharField(max_length=127, unique=True)
field_added.set_attributes_from_name("charfield_added")
field_to_alter = CharField(max_length=127, unique=True)
field_to_alter.set_attributes_from_name("charfield_altered")
altered_field = CharField(max_length=127, unique=False)
altered_field.set_attributes_from_name("charfield_altered")
with connection.schema_editor() as editor:
editor.add_field(ArticleTranslation, field_added)
editor.add_field(ArticleTranslation, field_to_alter)
self.assertEqual(len(editor.deferred_sql), 2)
editor.alter_field(ArticleTranslation, field_to_alter, altered_field)
self.assertEqual(len(editor.deferred_sql), 1)
self.assertIn("charfield_added", str(editor.deferred_sql[0].parts["name"]))
class SchemaIndexesNotPostgreSQLTests(TransactionTestCase):
available_apps = ["indexes"]