summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorMariusz Felisiak <felisiak.mariusz@gmail.com>2017-12-05 21:11:20 +0100
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2017-12-05 22:52:42 +0100
commit1decd0197d241b27d54bb12eca04b7e89a9ccba6 (patch)
tree657bb670845a295e4f59c42d23d662a92e6c6830 /tests
parent3e52fd7595f80ec162fc44798c29399b7e899b9b (diff)
[1.11.x] Refs #28876 -- Fixed incorrect foreign key constraint name for models with quoted db_table.
Thanks Simon Charette and Tim Graham for the review and Carlos E. C. Leite for the report. Backport of fc48047586a8f92262f55d9d2bfb976325844b23 from master
Diffstat (limited to 'tests')
-rw-r--r--tests/schema/tests.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/tests/schema/tests.py b/tests/schema/tests.py
index 8e868dfb0e..f3ad54b3bf 100644
--- a/tests/schema/tests.py
+++ b/tests/schema/tests.py
@@ -1784,6 +1784,28 @@ class SchemaTests(TransactionTestCase):
with connection.schema_editor() as editor:
editor.add_field(BookWithLongName, new_field)
+ @isolate_apps('schema')
+ @skipUnlessDBFeature('supports_foreign_keys')
+ def test_add_foreign_key_quoted_db_table(self):
+ class Author(Model):
+ class Meta:
+ db_table = '"table_author_double_quoted"'
+ app_label = 'schema'
+
+ class Book(Model):
+ author = ForeignKey(Author, CASCADE)
+
+ class Meta:
+ app_label = 'schema'
+
+ with connection.schema_editor() as editor:
+ editor.create_model(Author)
+ editor.create_model(Book)
+ if connection.vendor == 'mysql':
+ self.assertForeignKeyExists(Book, 'author_id', '"table_author_double_quoted"')
+ else:
+ self.assertForeignKeyExists(Book, 'author_id', 'table_author_double_quoted')
+
def test_add_foreign_object(self):
with connection.schema_editor() as editor:
editor.create_model(BookForeignObj)