(self)
| 608 | "supports_on_delete_db_cascade", |
| 609 | ) |
| 610 | def test_fk_alter_on_delete(self): |
| 611 | with connection.schema_editor() as editor: |
| 612 | editor.create_model(Author) |
| 613 | editor.create_model(Book) |
| 614 | self.assertForeignKeyExists(Book, "author_id", "schema_author") |
| 615 | # Change CASCADE to DB_CASCADE. |
| 616 | old_field = Book._meta.get_field("author") |
| 617 | new_field = ForeignKey(Author, DB_CASCADE) |
| 618 | new_field.set_attributes_from_name("author") |
| 619 | with ( |
| 620 | connection.schema_editor() as editor, |
| 621 | CaptureQueriesContext(connection) as ctx, |
| 622 | ): |
| 623 | editor.alter_field(Book, old_field, new_field) |
| 624 | self.assertForeignKeyExists(Book, "author_id", "schema_author") |
| 625 | self.assertIs( |
| 626 | any("ON DELETE" in query["sql"] for query in ctx.captured_queries), True |
| 627 | ) |
| 628 | # Change DB_CASCADE to CASCADE. |
| 629 | old_field = new_field |
| 630 | new_field = ForeignKey(Author, CASCADE) |
| 631 | new_field.set_attributes_from_name("author") |
| 632 | with ( |
| 633 | connection.schema_editor() as editor, |
| 634 | CaptureQueriesContext(connection) as ctx, |
| 635 | ): |
| 636 | editor.alter_field(Book, old_field, new_field) |
| 637 | self.assertForeignKeyExists(Book, "author_id", "schema_author") |
| 638 | self.assertIs( |
| 639 | any("ON DELETE" in query["sql"] for query in ctx.captured_queries), False |
| 640 | ) |
| 641 | |
| 642 | @isolate_apps("schema") |
| 643 | @skipUnlessDBFeature("supports_foreign_keys", "can_introspect_foreign_keys") |
nothing calls this directly
no test coverage detected