0001_initial.py 950 B

1234567891011121314151617181920212223242526272829303132
  1. # -*- coding: utf-8 -*-
  2. from __future__ import unicode_literals
  3. from django.db import migrations, models
  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. class Migration(migrations.Migration):
  10. atomic = False
  11. operations = [
  12. migrations.CreateModel(
  13. "Publisher",
  14. [
  15. ("name", models.CharField(primary_key=True, max_length=255)),
  16. ],
  17. ),
  18. migrations.RunPython(raise_error),
  19. migrations.CreateModel(
  20. "Book",
  21. [
  22. ("title", models.CharField(primary_key=True, max_length=255)),
  23. ("publisher", models.ForeignKey("migrations.Publisher", models.SET_NULL, null=True)),
  24. ],
  25. ),
  26. ]