diff options
Diffstat (limited to 'django/db/backends/sqlite3/introspection.py')
| -rw-r--r-- | django/db/backends/sqlite3/introspection.py | 30 |
1 files changed, 17 insertions, 13 deletions
diff --git a/django/db/backends/sqlite3/introspection.py b/django/db/backends/sqlite3/introspection.py index 0518641344..de6d6da465 100644 --- a/django/db/backends/sqlite3/introspection.py +++ b/django/db/backends/sqlite3/introspection.py @@ -239,6 +239,22 @@ class DatabaseIntrospection(BaseDatabaseIntrospection): 'pk': field[5], # undocumented } for field in cursor.fetchall()] + def _get_foreign_key_constraints(self, cursor, table_name): + constraints = {} + cursor.execute('PRAGMA foreign_key_list(%s)' % self.connection.ops.quote_name(table_name)) + for row in cursor.fetchall(): + # Remaining on_update/on_delete/match values are of no interest. + id_, _, table, from_, to = row[:5] + constraints['fk_%d' % id_] = { + 'columns': [from_], + 'primary_key': False, + 'unique': False, + 'foreign_key': (table, to), + 'check': False, + 'index': False, + } + return constraints + def get_constraints(self, cursor, table_name): """ Retrieve any constraints or keys (unique, pk, fk, check, index) across @@ -293,17 +309,5 @@ class DatabaseIntrospection(BaseDatabaseIntrospection): "check": False, "index": False, } - # Get foreign keys - cursor.execute('PRAGMA foreign_key_list(%s)' % self.connection.ops.quote_name(table_name)) - for row in cursor.fetchall(): - # Remaining on_update/on_delete/match values are of no interest here - id_, seq, table, from_, to = row[:5] - constraints['fk_%d' % id_] = { - 'columns': [from_], - 'primary_key': False, - 'unique': False, - 'foreign_key': (table, to), - 'check': False, - 'index': False, - } + constraints.update(self._get_foreign_key_constraints(cursor, table_name)) return constraints |
