Debian Codegraph @

tests/migrations/test_migrations_non_atomic/0001_initial.py

raw
1 from django.db import migrations, models
2
3
4 def raise_error(apps, schema_editor):
5 # Test operation in non-atomic migration is not wrapped in transaction
6 Publisher = apps.get_model("migrations", "Publisher")
7 Publisher.objects.create(name="Test Publisher")
8 raise RuntimeError("Abort migration")
9
10
11 class Migration(migrations.Migration):
12 atomic = False
13
14 operations = [
15 migrations.CreateModel(
16 "Publisher",
17 [
18 ("name", models.CharField(primary_key=True, max_length=255)),
19 ],
20 ),
21 migrations.RunPython(raise_error),
22 migrations.CreateModel(
23 "Book",
24 [
25 ("title", models.CharField(primary_key=True, max_length=255)),
26 (
27 "publisher",
28 models.ForeignKey(
29 "migrations.Publisher", models.SET_NULL, null=True
30 ),
31 ),
32 ],
33 ),
34 ]