mirror of
https://github.com/django/django.git
synced 2025-10-24 06:06:09 +00:00
Fixed #33288 -- Made SQLite introspection use information schema for relations.
Previous solution was using brittle and complex parsing rules to extract them from the SQL used to define the tables. Removed a now unnecessary unit test that ensured the removed parsing logic accounted for optional spacing.
This commit is contained in:
committed by
Mariusz Felisiak
parent
30ec7fe89a
commit
483e30c3d5
@@ -1,5 +1,3 @@
|
||||
from unittest import mock, skipUnless
|
||||
|
||||
from django.db import DatabaseError, connection
|
||||
from django.db.models import Index
|
||||
from django.test import TransactionTestCase, skipUnlessDBFeature
|
||||
@@ -152,22 +150,6 @@ class IntrospectionTests(TransactionTestCase):
|
||||
editor.add_field(Article, body)
|
||||
self.assertEqual(relations, expected_relations)
|
||||
|
||||
@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 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), 'table'])
|
||||
relations = connection.introspection.get_relations(cursor, 'mocked_table')
|
||||
self.assertEqual(relations, {'art_id': ('id', Article._meta.db_table)})
|
||||
|
||||
def test_get_primary_key_column(self):
|
||||
with connection.cursor() as cursor:
|
||||
primary_key_column = connection.introspection.get_primary_key_column(cursor, Article._meta.db_table)
|
||||
|
||||
Reference in New Issue
Block a user