From 10c40dc591e5005a385b1a35a2613b4d981ec202 Mon Sep 17 00:00:00 2001 From: Roland Szabo Date: Thu, 3 Mar 2022 15:22:28 +0200 Subject: [PATCH] Fix migration --- backend/api/migrations/0017_example_uuid.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/backend/api/migrations/0017_example_uuid.py b/backend/api/migrations/0017_example_uuid.py index 5d70fbfd..8630284c 100644 --- a/backend/api/migrations/0017_example_uuid.py +++ b/backend/api/migrations/0017_example_uuid.py @@ -5,6 +5,13 @@ import uuid from django.db import migrations, models +def create_uuid(apps, schema_editor): + Example = apps.get_model('api', 'example') + for example in Example.objects.all(): + example.uuid = uuid.uuid4() + example.save() + + class Migration(migrations.Migration): dependencies = [ @@ -15,6 +22,12 @@ class Migration(migrations.Migration): migrations.AddField( model_name="example", name="uuid", - field=models.UUIDField(db_index=True, default=uuid.uuid4, editable=False, unique=True), + field=models.UUIDField(editable=False, blank=True, null=True), ), - ] + migrations.RunPython(create_uuid), + migrations.AlterField( + model_name='example', + name='uuid', + field=models.UUIDField(db_index=True, unique=True) + ) + ] \ No newline at end of file