From 344d28a13412b0593fed14bdf213f99b94105959 Mon Sep 17 00:00:00 2001 From: Dane Hillard Date: Mon, 2 Jul 2018 23:59:39 -0400 Subject: [PATCH] Fix constraint introspection for table indices --- lib/mysql/connector/django/introspection.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/mysql/connector/django/introspection.py b/lib/mysql/connector/django/introspection.py index e82623f..9c5be4a 100644 --- a/lib/mysql/connector/django/introspection.py +++ b/lib/mysql/connector/django/introspection.py @@ -5,6 +5,8 @@ from collections import namedtuple import django +from django.db.models.indexes import Index + if django.VERSION >= (1, 8): from django.db.backends.base.introspection import ( BaseDatabaseIntrospection, FieldInfo, TableInfo @@ -348,8 +350,7 @@ def get_constraints(self, cursor, table_name): # Now add in the indexes cursor.execute("SHOW INDEX FROM %s" % self.connection.ops.quote_name( table_name)) - for table, non_unique, index, colseq, column in [x[:5] for x in - cursor.fetchall()]: + for table, non_unique, index, colseq, column, type_ in [x[:5] + (x[10],) for x in cursor.fetchall()]: if index not in constraints: constraints[index] = { 'columns': OrderedSet(), @@ -360,6 +361,7 @@ def get_constraints(self, cursor, table_name): 'foreign_key': None, } constraints[index]['index'] = True + constraints[index]['type'] = Index.suffix if type_ == 'BTREE' else type_.lower() constraints[index]['columns'].add(column) # Convert the sorted sets to lists for constraint in constraints.values():