From 5a2b714b49e2f15823de0fc5c76a08ef08a62b14 Mon Sep 17 00:00:00 2001 From: Evert-R Date: Fri, 22 Nov 2024 15:53:43 +0100 Subject: [PATCH] catch for duplictate slugs already in databae --- .../migrations/0061_migrate_slugs_to_unique_temp_field.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/backend/experiment/migrations/0061_migrate_slugs_to_unique_temp_field.py b/backend/experiment/migrations/0061_migrate_slugs_to_unique_temp_field.py index c2d9978e9..8ac679172 100644 --- a/backend/experiment/migrations/0061_migrate_slugs_to_unique_temp_field.py +++ b/backend/experiment/migrations/0061_migrate_slugs_to_unique_temp_field.py @@ -8,7 +8,10 @@ class Migration(migrations.Migration): def forwards_func(apps, schema_editor): Experiment = apps.get_model('experiment', 'Experiment') for experiment in Experiment.objects.all(): - experiment.slug_temp = experiment.slug + if Experiment.objects.filter(slug=experiment.slug).count() > 1: + experiment.slug_temp = f"{experiment.slug}-{experiment.id}" + else: + experiment.slug_temp = experiment.slug experiment.save() def reverse_func(apps, schema_editor):