MCPcopy
hub / github.com/django/django / test_add_inline_fk_index_update_data

Method test_add_inline_fk_index_update_data

tests/schema/tests.py:472–491  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

470 )
471 @isolate_apps("schema")
472 def test_add_inline_fk_index_update_data(self):
473 class Node(Model):
474 class Meta:
475 app_label = "schema"
476
477 with connection.schema_editor() as editor:
478 editor.create_model(Node)
479 # Add an inline foreign key, update data, and an index in the same
480 # transaction.
481 new_field = ForeignKey(Node, CASCADE, related_name="new_fk", null=True)
482 new_field.set_attributes_from_name("new_parent_fk")
483 parent = Node.objects.create()
484 with connection.schema_editor() as editor:
485 editor.add_field(Node, new_field)
486 Node._meta.add_field(new_field)
487 editor.execute("UPDATE schema_node SET new_parent_fk_id = %s;", [parent.pk])
488 editor.add_index(
489 Node, Index(fields=["new_parent_fk"], name="new_parent_inline_fk_idx")
490 )
491 self.assertIn("new_parent_fk_id", self.get_indexes(Node._meta.db_table))
492
493 @skipUnlessDBFeature("supports_foreign_keys")
494 def test_char_field_with_db_index_to_fk(self):

Callers

nothing calls this directly

Calls 10

get_indexesMethod · 0.95
ForeignKeyClass · 0.90
IndexClass · 0.90
schema_editorMethod · 0.80
create_modelMethod · 0.45
createMethod · 0.45
add_fieldMethod · 0.45
executeMethod · 0.45
add_indexMethod · 0.45

Tested by

no test coverage detected