fix eventinstance uuid migration with this abomination https://docs.djangoproject.com/en/dev/howto/writing-migrations/#migrations-that-add-unique-fields
This commit is contained in:
parent
b235cb9683
commit
eb18fc2ec5
|
@ -19,7 +19,7 @@ class Migration(migrations.Migration):
|
||||||
default=uuid.uuid4,
|
default=uuid.uuid4,
|
||||||
editable=False,
|
editable=False,
|
||||||
help_text="This field is mostly here to keep Frab happy, it is not the PK of the model",
|
help_text="This field is mostly here to keep Frab happy, it is not the PK of the model",
|
||||||
unique=True,
|
null=True,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
|
|
23
src/program/migrations/0081_populate_eventinstance_uuids.py
Normal file
23
src/program/migrations/0081_populate_eventinstance_uuids.py
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
# Generated by Django 3.0.3 on 2020-02-22 15:13
|
||||||
|
|
||||||
|
import uuid
|
||||||
|
|
||||||
|
from django.db import migrations
|
||||||
|
|
||||||
|
|
||||||
|
def gen_uuid(apps, schema_editor):
|
||||||
|
MyModel = apps.get_model("program", "EventInstance")
|
||||||
|
for row in MyModel.objects.all():
|
||||||
|
row.uuid = uuid.uuid4()
|
||||||
|
row.save(update_fields=["uuid"])
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
("program", "0080_auto_20200222_1547"),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RunPython(gen_uuid),
|
||||||
|
]
|
25
src/program/migrations/0082_eventinstance_uuid_not_null.py
Normal file
25
src/program/migrations/0082_eventinstance_uuid_not_null.py
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
# Generated by Django 3.0.3 on 2020-02-22 15:13
|
||||||
|
|
||||||
|
import uuid
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
("program", "0081_populate_eventinstance_uuids"),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name="eventinstance",
|
||||||
|
name="uuid",
|
||||||
|
field=models.UUIDField(
|
||||||
|
default=uuid.uuid4,
|
||||||
|
editable=False,
|
||||||
|
help_text="This field is mostly here to keep Frab happy, it is not the PK of the model",
|
||||||
|
unique=True,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
]
|
Loading…
Reference in a new issue