mirror of
https://github.com/django/django.git
synced 2025-10-24 06:06:09 +00:00
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.
This commit is contained in:
@@ -1914,6 +1914,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)
|
||||
|
||||
Reference in New Issue
Block a user