mirror of
https://github.com/django/django.git
synced 2025-10-31 09:41:08 +00:00
Fixed #27098 -- Deprecated DatabaseIntrospection.get_indexes
Thanks Akshesh <aksheshdoshi@gmail.com> for help with the PostgreSQL query. Thanks Tim Graham for the review.
This commit is contained in:
@@ -105,12 +105,20 @@ class SchemaTests(TransactionTestCase):
|
||||
raise DatabaseError("Table does not exist (empty pragma)")
|
||||
return columns
|
||||
|
||||
def get_primary_key(self, table):
|
||||
with connection.cursor() as cursor:
|
||||
return connection.introspection.get_primary_key_column(cursor, table)
|
||||
|
||||
def get_indexes(self, table):
|
||||
"""
|
||||
Get the indexes on the table using a new cursor.
|
||||
"""
|
||||
with connection.cursor() as cursor:
|
||||
return connection.introspection.get_indexes(cursor, table)
|
||||
return [
|
||||
c['columns'][0]
|
||||
for c in connection.introspection.get_constraints(cursor, table).values()
|
||||
if c['index'] and len(c['columns']) == 1
|
||||
]
|
||||
|
||||
def get_constraints(self, table):
|
||||
"""
|
||||
@@ -1685,9 +1693,7 @@ class SchemaTests(TransactionTestCase):
|
||||
with connection.schema_editor() as editor:
|
||||
editor.create_model(Tag)
|
||||
# Ensure the table is there and has the right PK
|
||||
self.assertTrue(
|
||||
self.get_indexes(Tag._meta.db_table)['id']['primary_key'],
|
||||
)
|
||||
self.assertEqual(self.get_primary_key(Tag._meta.db_table), 'id')
|
||||
# Alter to change the PK
|
||||
id_field = Tag._meta.get_field("id")
|
||||
old_field = Tag._meta.get_field("slug")
|
||||
@@ -1702,9 +1708,7 @@ class SchemaTests(TransactionTestCase):
|
||||
'id',
|
||||
self.get_indexes(Tag._meta.db_table),
|
||||
)
|
||||
self.assertTrue(
|
||||
self.get_indexes(Tag._meta.db_table)['slug']['primary_key'],
|
||||
)
|
||||
self.assertEqual(self.get_primary_key(Tag._meta.db_table), 'slug')
|
||||
|
||||
def test_context_manager_exit(self):
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user