(self)
| 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): |
nothing calls this directly
no test coverage detected