MCPcopy
hub / github.com/django/django / get_constraints_count

Method get_constraints_count

tests/schema/tests.py:269–287  ·  view source on GitHub ↗

Return a dict with keys 'fks', 'uniques, and 'indexes' indicating the number of foreign keys, unique constraints, and indexes on `table`.`column`. The `fk_to` argument is a 2-tuple specifying the expected foreign key relationship's (table, column).

(self, table, column, fk_to)

Source from the content-addressed store, hash-verified

267 self.assertEqual(database_default, expected_default)
268
269 def get_constraints_count(self, table, column, fk_to):
270 """
271 Return a dict with keys 'fks', 'uniques, and 'indexes' indicating the
272 number of foreign keys, unique constraints, and indexes on
273 `table`.`column`. The `fk_to` argument is a 2-tuple specifying the
274 expected foreign key relationship's (table, column).
275 """
276 with connection.cursor() as cursor:
277 constraints = connection.introspection.get_constraints(cursor, table)
278 counts = {"fks": 0, "uniques": 0, "indexes": 0}
279 for c in constraints.values():
280 if c["columns"] == [column]:
281 if c["foreign_key"] == fk_to:
282 counts["fks"] += 1
283 if c["unique"]:
284 counts["uniques"] += 1
285 elif c["index"]:
286 counts["indexes"] += 1
287 return counts
288
289 def get_column_collation(self, table, column):
290 with connection.cursor() as cursor:

Calls 3

cursorMethod · 0.80
get_constraintsMethod · 0.45
valuesMethod · 0.45

Tested by

no test coverage detected