MCPcopy
hub / github.com/django/django / _test_m2m_db_constraint

Method _test_m2m_db_constraint

tests/schema/tests.py:698–723  ·  view source on GitHub ↗
(self, M2MFieldClass)

Source from the content-addressed store, hash-verified

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):

Calls 6

schema_editorMethod · 0.80
create_modelMethod · 0.45
allMethod · 0.45
contribute_to_classMethod · 0.45
add_fieldMethod · 0.45

Tested by

no test coverage detected