Refs #33288 -- Removed SQLite's DatabaseIntrospection._get_foreign_key_constraints().
The get_relations() method returns the exact same data in a more generic format.
This commit is contained in:
parent
483e30c3d5
commit
560ff988dd
|
@ -137,22 +137,6 @@ class DatabaseIntrospection(BaseDatabaseIntrospection):
|
||||||
return name
|
return name
|
||||||
return None
|
return None
|
||||||
|
|
||||||
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 _parse_column_or_constraint_definition(self, tokens, columns):
|
def _parse_column_or_constraint_definition(self, tokens, columns):
|
||||||
token = None
|
token = None
|
||||||
is_constraint_definition = None
|
is_constraint_definition = None
|
||||||
|
@ -349,7 +333,18 @@ class DatabaseIntrospection(BaseDatabaseIntrospection):
|
||||||
"check": False,
|
"check": False,
|
||||||
"index": False,
|
"index": False,
|
||||||
}
|
}
|
||||||
constraints.update(self._get_foreign_key_constraints(cursor, table_name))
|
relations = enumerate(self.get_relations(cursor, table_name).items())
|
||||||
|
constraints.update({
|
||||||
|
f'fk_{index}': {
|
||||||
|
'columns': [column_name],
|
||||||
|
'primary_key': False,
|
||||||
|
'unique': False,
|
||||||
|
'foreign_key': (ref_table_name, ref_column_name),
|
||||||
|
'check': False,
|
||||||
|
'index': False,
|
||||||
|
}
|
||||||
|
for index, (column_name, (ref_column_name, ref_table_name)) in relations
|
||||||
|
})
|
||||||
return constraints
|
return constraints
|
||||||
|
|
||||||
def _get_index_columns_orders(self, sql):
|
def _get_index_columns_orders(self, sql):
|
||||||
|
|
|
@ -75,9 +75,8 @@ class DatabaseSchemaEditor(BaseDatabaseSchemaEditor):
|
||||||
for other_table in self.connection.introspection.get_table_list(cursor):
|
for other_table in self.connection.introspection.get_table_list(cursor):
|
||||||
if ignore_self and other_table.name == table_name:
|
if ignore_self and other_table.name == table_name:
|
||||||
continue
|
continue
|
||||||
constraints = self.connection.introspection._get_foreign_key_constraints(cursor, other_table.name)
|
relations = self.connection.introspection.get_relations(cursor, other_table.name)
|
||||||
for constraint in constraints.values():
|
for constraint_column, constraint_table in relations.values():
|
||||||
constraint_table, constraint_column = constraint['foreign_key']
|
|
||||||
if (constraint_table == table_name and
|
if (constraint_table == table_name and
|
||||||
(column_name is None or constraint_column == column_name)):
|
(column_name is None or constraint_column == column_name)):
|
||||||
return True
|
return True
|
||||||
|
|
Loading…
Reference in New Issue