summaryrefslogtreecommitdiff
path: root/tests/schema
diff options
context:
space:
mode:
authorHannes Ljungberg <hannes.ljungberg@gmail.com>2021-05-23 14:25:54 +0200
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2021-05-24 06:31:48 +0200
commit7ef2398e814e044d54b68359d473cc64902a8c31 (patch)
tree50aac8a4b17ae09d2c36db84a026a5e166ce87c2 /tests/schema
parent5e04e84d67da8163f365e9f5fcd169e2630e2873 (diff)
downloaddjango-7ef2398e814e044d54b68359d473cc64902a8c31.tar.gz
Fixed #32777 -- Passed table reference as a string to DatabaseSchemaEditor._index_columns().
Diffstat (limited to 'tests/schema')
-rw-r--r--tests/schema/tests.py16
1 files changed, 16 insertions, 0 deletions
diff --git a/tests/schema/tests.py b/tests/schema/tests.py
index c5f5bd2e85..036ac29dce 100644
--- a/tests/schema/tests.py
+++ b/tests/schema/tests.py
@@ -2198,6 +2198,22 @@ class SchemaTests(TransactionTestCase):
AuthorWithUniqueNameAndBirthday._meta.constraints = []
editor.remove_constraint(AuthorWithUniqueNameAndBirthday, constraint)
+ def test_unique_constraint(self):
+ with connection.schema_editor() as editor:
+ editor.create_model(Author)
+ constraint = UniqueConstraint(fields=['name'], name='name_uq')
+ # Add constraint.
+ with connection.schema_editor() as editor:
+ editor.add_constraint(Author, constraint)
+ sql = constraint.create_sql(Author, editor)
+ table = Author._meta.db_table
+ self.assertIs(sql.references_table(table), True)
+ self.assertIs(sql.references_column(table, 'name'), True)
+ # Remove constraint.
+ with connection.schema_editor() as editor:
+ editor.remove_constraint(Author, constraint)
+ self.assertNotIn(constraint.name, self.get_constraints(table))
+
@skipUnlessDBFeature('supports_expression_indexes')
def test_func_unique_constraint(self):
with connection.schema_editor() as editor: