          new_field.contribute_to_class(LocalBookWithM2M, "uniques")
          with connection.schema_editor() as editor:
              editor.alter_field(LocalBookWithM2M, old_field, new_field)
          # Ensure old M2M is gone
          self.assertRaises(
              DatabaseError,
              self.column_classes, LocalBookWithM2M._meta.get_field("tags").remote_field.through
          )
  
          # This model looks like the new model and is used for teardown.
          opts = LocalBookWithM2M._meta
          opts.local_many_to_many.remove(old_field)
          # Ensure the new M2M exists and points to UniqueTest
 
</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, new_field.remote_field.through)
 </s> add         with self.assertRaises(DatabaseError):
            self.column_classes(new_field.remote_field.through) </s> remove         self.assertRaises(IntegrityError, UniqueTest.objects.create, year=2012, slug="foo")
 </s> add         with self.assertRaises(IntegrityError):
            UniqueTest.objects.create(year=2012, 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(InvalidSessionKey,
                          self.backend()._key_to_file, "a\\b\\c")
 </s> add         with self.assertRaises(InvalidSessionKey):
            self.backend()._key_to_file("a\\b\\c")
        with self.assertRaises(DatabaseError):
            self.column_classes(LocalBookWithM2M._meta.get_field("tags").remote_field.through)
          new_field.contribute_to_class(LocalBookWithM2M, "uniques")
          with connection.schema_editor() as editor:
              editor.alter_field(LocalBookWithM2M, old_field, new_field)
          # Ensure old M2M is gone
        with self.assertRaises(DatabaseError):
            self.column_classes(LocalBookWithM2M._meta.get_field("tags").remote_field.through)
        with self.assertRaises(DatabaseError):
            self.column_classes(LocalBookWithM2M._meta.get_field("tags").remote_field.through)
        with self.assertRaises(DatabaseError):
            self.column_classes(LocalBookWithM2M._meta.get_field("tags").remote_field.through)
        with self.assertRaises(DatabaseError):
            self.column_classes(LocalBookWithM2M._meta.get_field("tags").remote_field.through)
  
          # This model looks like the new model and is used for teardown.
          opts = LocalBookWithM2M._meta
          opts.local_many_to_many.remove(old_field)
          # Ensure the new M2M exists and points to UniqueTest
keep keep keep keep replace replace replace replace keep keep keep keep keep
 Refs #26022 -- Used context manager version of assertRaises in tests. 
tests/schema/tests.py