MCPcopy
hub / github.com/django/django / assertForeignKeyExists

Method assertForeignKeyExists

tests/schema/tests.py:326–339  ·  view source on GitHub ↗

Fail if the FK constraint on `model.Meta.db_table`.`column` to `expected_fk_table`.id doesn't exist.

(self, model, column, expected_fk_table, field="id")

Source from the content-addressed store, hash-verified

324 )
325
326 def assertForeignKeyExists(self, model, column, expected_fk_table, field="id"):
327 """
328 Fail if the FK constraint on `model.Meta.db_table`.`column` to
329 `expected_fk_table`.id doesn't exist.
330 """
331 if not connection.features.can_introspect_foreign_keys:
332 return
333 constraints = self.get_constraints(model._meta.db_table)
334 constraint_fk = None
335 for details in constraints.values():
336 if details["columns"] == [column] and details["foreign_key"]:
337 constraint_fk = details["foreign_key"]
338 break
339 self.assertEqual(constraint_fk, (expected_fk_table, field))
340
341 def assertForeignKeyNotExists(self, model, column, expected_fk_table):
342 if not connection.features.can_introspect_foreign_keys:

Callers 15

test_fkMethod · 0.95
test_inline_fkMethod · 0.95
test_fk_to_proxyMethod · 0.95
test_fk_db_constraintMethod · 0.95
test_alter_fkMethod · 0.95
test_alter_to_fkMethod · 0.95
test_alter_o2o_to_fkMethod · 0.95

Calls 2

get_constraintsMethod · 0.95
valuesMethod · 0.45

Tested by

no test coverage detected