1. from django.db import migrations, models
    
  2. 
    
  3. 
    
  4. def raise_error(apps, schema_editor):
    
  5.     # Test atomic operation in non-atomic migration is wrapped in transaction
    
  6.     Editor = apps.get_model("migrations", "Editor")
    
  7.     Editor.objects.create(name="Test Editor")
    
  8.     raise RuntimeError("Abort migration")
    
  9. 
    
  10. 
    
  11. class Migration(migrations.Migration):
    
  12.     atomic = False
    
  13. 
    
  14.     operations = [
    
  15.         migrations.CreateModel(
    
  16.             "Editor",
    
  17.             [
    
  18.                 ("name", models.CharField(primary_key=True, max_length=255)),
    
  19.             ],
    
  20.         ),
    
  21.         migrations.RunPython(raise_error, reverse_code=raise_error, atomic=True),
    
  22.     ]