Creating a FK to a proxy model creates database constraints.
(self)
| 547 | |
| 548 | @skipUnlessDBFeature("supports_foreign_keys") |
| 549 | def test_fk_to_proxy(self): |
| 550 | "Creating a FK to a proxy model creates database constraints." |
| 551 | |
| 552 | class AuthorProxy(Author): |
| 553 | class Meta: |
| 554 | app_label = "schema" |
| 555 | apps = new_apps |
| 556 | proxy = True |
| 557 | |
| 558 | class AuthorRef(Model): |
| 559 | author = ForeignKey(AuthorProxy, on_delete=CASCADE) |
| 560 | |
| 561 | class Meta: |
| 562 | app_label = "schema" |
| 563 | apps = new_apps |
| 564 | |
| 565 | self.local_models = [AuthorProxy, AuthorRef] |
| 566 | |
| 567 | # Create the table |
| 568 | with connection.schema_editor() as editor: |
| 569 | editor.create_model(Author) |
| 570 | editor.create_model(AuthorRef) |
| 571 | self.assertForeignKeyExists(AuthorRef, "author_id", "schema_author") |
| 572 | |
| 573 | @skipUnlessDBFeature("supports_foreign_keys", "can_introspect_foreign_keys") |
| 574 | def test_fk_db_constraint(self): |
nothing calls this directly
no test coverage detected