(self, M2MFieldClass)
| 696 | self.assertForeignKeyNotExists(BookWeak, "author_id", "schema_author") |
| 697 | |
| 698 | def _test_m2m_db_constraint(self, M2MFieldClass): |
| 699 | class LocalAuthorWithM2M(Model): |
| 700 | name = CharField(max_length=255) |
| 701 | |
| 702 | class Meta: |
| 703 | app_label = "schema" |
| 704 | apps = new_apps |
| 705 | |
| 706 | self.local_models = [LocalAuthorWithM2M] |
| 707 | |
| 708 | # Create the table |
| 709 | with connection.schema_editor() as editor: |
| 710 | editor.create_model(Tag) |
| 711 | editor.create_model(LocalAuthorWithM2M) |
| 712 | # Initial tables are there |
| 713 | list(LocalAuthorWithM2M.objects.all()) |
| 714 | list(Tag.objects.all()) |
| 715 | # Make a db_constraint=False FK |
| 716 | new_field = M2MFieldClass(Tag, related_name="authors", db_constraint=False) |
| 717 | new_field.contribute_to_class(LocalAuthorWithM2M, "tags") |
| 718 | # Add the field |
| 719 | with connection.schema_editor() as editor: |
| 720 | editor.add_field(LocalAuthorWithM2M, new_field) |
| 721 | self.assertForeignKeyNotExists( |
| 722 | new_field.remote_field.through, "tag_id", "schema_tag" |
| 723 | ) |
| 724 | |
| 725 | @skipUnlessDBFeature("supports_foreign_keys") |
| 726 | def test_m2m_db_constraint(self): |
no test coverage detected