mirror of
https://github.com/django/django.git
synced 2025-08-03 18:38:50 +00:00
Fixed #27372 -- Fixed introspection of SQLite foreign keys with spaces in DDL.
Thanks samuller for the report and initial patch.
This commit is contained in:
parent
09da1e79de
commit
f28d29e8b7
2 changed files with 14 additions and 12 deletions
|
@ -143,17 +143,19 @@ class IntrospectionTests(TransactionTestCase):
|
|||
|
||||
@skipUnless(connection.vendor == 'sqlite', "This is an sqlite-specific issue")
|
||||
def test_get_relations_alt_format(self):
|
||||
"""With SQLite, foreign keys can be added with different syntaxes."""
|
||||
with connection.cursor() as cursor:
|
||||
cursor.fetchone = mock.Mock(
|
||||
return_value=[
|
||||
"CREATE TABLE track(id, art_id INTEGER, FOREIGN KEY(art_id) REFERENCES {}(id));".format(
|
||||
Article._meta.db_table
|
||||
)
|
||||
]
|
||||
)
|
||||
relations = connection.introspection.get_relations(cursor, 'mocked_table')
|
||||
self.assertEqual(relations, {'art_id': ('id', Article._meta.db_table)})
|
||||
"""
|
||||
With SQLite, foreign keys can be added with different syntaxes and
|
||||
formatting.
|
||||
"""
|
||||
create_table_statements = [
|
||||
"CREATE TABLE track(id, art_id INTEGER, FOREIGN KEY(art_id) REFERENCES {}(id));",
|
||||
"CREATE TABLE track(id, art_id INTEGER, FOREIGN KEY (art_id) REFERENCES {}(id));"
|
||||
]
|
||||
for statement in create_table_statements:
|
||||
with connection.cursor() as cursor:
|
||||
cursor.fetchone = mock.Mock(return_value=[statement.format(Article._meta.db_table)])
|
||||
relations = connection.introspection.get_relations(cursor, 'mocked_table')
|
||||
self.assertEqual(relations, {'art_id': ('id', Article._meta.db_table)})
|
||||
|
||||
@skipUnlessDBFeature('can_introspect_foreign_keys')
|
||||
def test_get_key_columns(self):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue