"Fossies" - the Fresh Open Source Software Archive

Member "Django-1.11.25/tests/migrations/test_migrations_non_atomic/0001_initial.py" (1 Oct 2019, 950 Bytes) of package /linux/www/Django-1.11.25.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

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