Ticket #29496: 0027_example_layout_layout_field_uuids.py

File 0027_example_layout_layout_field_uuids.py, 2.2 KB (added by Peter Levi, 6 years ago)

migration 3 - schema changes to remove old ID fields, rename temporary FKs back to the original names, and introduce the primary_keys. Fails on step 4.

Line 
1# Generated by Django 2.0.6 on 2018-06-12 12:19
2from django.db import migrations, models
3import uuid
4
5
6from common.migration_utils import CustomMigration
7
8
9def step(x):
10 def f(*args):
11 print('\n\n\n\n\n\n')
12 print('==================== STEP ========================= ', x, ' =====================')
13 print('\n\n')
14 return f
15
16
17class Migration(CustomMigration):
18
19 dependencies = [
20 ('vario', '0026_populate_and_match_layout_uuids'),
21 ]
22
23 operations = [
24 migrations.RunPython(code=step(1)),
25 # we no longer need the link to layout id, remove it
26 migrations.RemoveField(
27 model_name='layoutfield',
28 name='layout',
29 ),
30
31 migrations.RunPython(code=step(2)),
32 # and rename the link to layout uuid to be called layout
33 migrations.RenameField(
34 model_name='layoutfield',
35 old_name='temp_layout',
36 new_name='layout'
37 ),
38
39 migrations.RunPython(code=step(3)),
40 # remove the id PK in ExampleLayout
41 migrations.RemoveField(
42 model_name='examplelayout',
43 name='id',
44 ),
45
46 migrations.RunPython(code=step(4)),
47 # and make the uuid the new PK
48 migrations.AlterField(
49 model_name='examplelayout',
50 name='uuid',
51 field=models.UUIDField(default=uuid.uuid4, primary_key=True, editable=False),
52 ),
53
54 migrations.RunPython(code=step(5)),
55 # remove the id PK in LayoutField
56 migrations.RemoveField(
57 model_name='layoutfield',
58 name='id',
59 ),
60
61 migrations.RunPython(code=step(6)),
62 # and make the uuid the new PK
63 migrations.AlterField(
64 model_name='layoutfield',
65 name='uuid',
66 field=models.UUIDField(default=uuid.uuid4, primary_key=True, editable=False),
67 ),
68
69 migrations.RunPython(code=step(7)),
70 # and make the uuid link to ExampleLayout a proper FK
71 migrations.AlterField(
72 model_name='layoutfield',
73 name='layout',
74 field=models.ForeignKey(on_delete=models.deletion.CASCADE, related_name='fields', to='vario.ExampleLayout'),
75 ),
76
77 migrations.RunPython(code=step(8)),
78 ]
Back to Top