summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorSimon Charette <charette.s@gmail.com>2020-06-23 23:43:22 -0400
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2020-06-24 08:59:43 +0200
commitb8cb14e8a0d49a1544e3b2d6dbe40ab015bf9a8e (patch)
tree36f0e0e13ee80a86113220cf5bf253e1c415364f /tests
parentac0ff7d7001bdf2c6669857ea184656d097bd603 (diff)
[3.1.x] Fixed #31735 -- Fixed migrations crash on namespaced inline FK addition on PostgreSQL.
The namespace of the constraint must be included when making the constraint immediate. Regression in 22ce5d0031bd795ade081394043833e82046016c. Thanks Rodrigo Estevao for the report. Backport of 2e8941b6f90e65ffad3f07083b8de59e8ed29767 from master
Diffstat (limited to 'tests')
-rw-r--r--tests/schema/tests.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/tests/schema/tests.py b/tests/schema/tests.py
index 9aa1e239ac..59fe66953d 100644
--- a/tests/schema/tests.py
+++ b/tests/schema/tests.py
@@ -3059,6 +3059,35 @@ class SchemaTests(TransactionTestCase):
student = Student.objects.create(name='Some man')
doc.students.add(student)
+ @isolate_apps('schema')
+ @unittest.skipUnless(connection.vendor == 'postgresql', 'PostgreSQL specific db_table syntax.')
+ def test_namespaced_db_table_foreign_key_reference(self):
+ with connection.cursor() as cursor:
+ cursor.execute('CREATE SCHEMA django_schema_tests')
+
+ def delete_schema():
+ with connection.cursor() as cursor:
+ cursor.execute('DROP SCHEMA django_schema_tests CASCADE')
+
+ self.addCleanup(delete_schema)
+
+ class Author(Model):
+ class Meta:
+ app_label = 'schema'
+
+ class Book(Model):
+ class Meta:
+ app_label = 'schema'
+ db_table = '"django_schema_tests"."schema_book"'
+
+ author = ForeignKey(Author, CASCADE)
+ author.set_attributes_from_name('author')
+
+ with connection.schema_editor() as editor:
+ editor.create_model(Author)
+ editor.create_model(Book)
+ editor.add_field(Book, author)
+
def test_rename_table_renames_deferred_sql_references(self):
atomic_rename = connection.features.supports_atomic_references_rename
with connection.schema_editor(atomic=atomic_rename) as editor: