summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/schema/tests.py31
1 files changed, 31 insertions, 0 deletions
diff --git a/tests/schema/tests.py b/tests/schema/tests.py
index e325fa0c88..c0f0e52a63 100644
--- a/tests/schema/tests.py
+++ b/tests/schema/tests.py
@@ -2676,6 +2676,37 @@ class SchemaTests(TransactionTestCase):
with self.assertRaises(IntegrityError):
Tag.objects.create(title="bar", slug="foo")
+ def test_remove_ignored_unique_constraint_not_create_fk_index(self):
+ with connection.schema_editor() as editor:
+ editor.create_model(Author)
+ editor.create_model(Book)
+ constraint = UniqueConstraint(
+ "author",
+ condition=Q(title__in=["tHGttG", "tRatEotU"]),
+ name="book_author_condition_uniq",
+ )
+ # Add unique constraint.
+ with connection.schema_editor() as editor:
+ editor.add_constraint(Book, constraint)
+ old_constraints = self.get_constraints_for_column(
+ Book,
+ Book._meta.get_field("author").column,
+ )
+ # Remove unique constraint.
+ with connection.schema_editor() as editor:
+ editor.remove_constraint(Book, constraint)
+ new_constraints = self.get_constraints_for_column(
+ Book,
+ Book._meta.get_field("author").column,
+ )
+ # Redundant foreign key index is not added.
+ self.assertEqual(
+ len(old_constraints) - 1
+ if connection.features.supports_partial_indexes
+ else len(old_constraints),
+ len(new_constraints),
+ )
+
@skipUnlessDBFeature("allows_multiple_constraints_on_same_fields")
def test_remove_field_unique_does_not_remove_meta_constraints(self):
with connection.schema_editor() as editor: