          # Create an M2M field
          new_field = M2MFieldClass("schema.TagM2MTest", related_name="authors")
          new_field.contribute_to_class(LocalAuthorWithM2M, "tags")
          # Ensure there's no m2m table there
          self.assertRaises(DatabaseError, self.column_classes, new_field.remote_field.through)
          # Add the field
          with connection.schema_editor() as editor:
              editor.add_field(LocalAuthorWithM2M, new_field)
          # Ensure there is now an m2m table there
          columns = self.column_classes(new_field.remote_field.through)
 
</s> remove         self.assertRaises(DatabaseError, self.column_classes, new_field.remote_field.through)
 </s> add         with self.assertRaises(DatabaseError):
            self.column_classes(new_field.remote_field.through) </s> remove         self.assertRaises(
            DatabaseError,
            self.column_classes, LocalBookWithM2M._meta.get_field("tags").remote_field.through
        )
 </s> add         with self.assertRaises(DatabaseError):
            self.column_classes(LocalBookWithM2M._meta.get_field("tags").remote_field.through) </s> remove         self.assertRaises(IntegrityError, Tag.objects.create, title="bar", slug="foo")
 </s> add         with self.assertRaises(IntegrityError):
            Tag.objects.create(title="bar", slug="foo") </s> remove         self.assertRaises(IntegrityError, Tag.objects.create, title="bar", slug="foo")
 </s> add         with self.assertRaises(IntegrityError):
            Tag.objects.create(title="bar", slug="foo") </s> remove         self.assertRaises(
            DatabaseError,
            lambda: list(Author.objects.all()),
        )
 </s> add         with self.assertRaises(DatabaseError):
            list(Author.objects.all())
        with self.assertRaises(DatabaseError):
            self.column_classes(new_field.remote_field.through)
          # Create an M2M field
          new_field = M2MFieldClass("schema.TagM2MTest", related_name="authors")
          new_field.contribute_to_class(LocalAuthorWithM2M, "tags")
          # Ensure there's no m2m table there
        with self.assertRaises(DatabaseError):
            self.column_classes(new_field.remote_field.through)
          # Add the field
          with connection.schema_editor() as editor:
              editor.add_field(LocalAuthorWithM2M, new_field)
          # Ensure there is now an m2m table there
          columns = self.column_classes(new_field.remote_field.through)
keep keep keep keep replace keep keep keep keep keep
 Refs #26022 -- Used context manager version of assertRaises in tests. 
tests/schema/tests.py