diff --git a/backend/code_review_backend/issues/migrations/0015_remove_repository_phid_alter_repository_id.py b/backend/code_review_backend/issues/migrations/0015_remove_repository_phid_alter_repository_id.py index a69bad4cd..408102d54 100644 --- a/backend/code_review_backend/issues/migrations/0015_remove_repository_phid_alter_repository_id.py +++ b/backend/code_review_backend/issues/migrations/0015_remove_repository_phid_alter_repository_id.py @@ -1,5 +1,6 @@ # Generated by Django 5.1.2 on 2024-11-18 15:53 +from django.conf import settings from django.db import migrations, models @@ -23,3 +24,17 @@ class Migration(migrations.Migration): options={"ordering": ("id",), "verbose_name_plural": "repositories"}, ), ] + if "postgresql" in settings.DATABASES["default"]["ENGINE"]: + # Correctly initialize the sequence with PostgreSQL + migrations.append( + migrations.RunSQL( + """ + SELECT setval( + pg_get_serial_sequence('issues_repository', 'id'), + coalesce(max(id)+1, 0), + false + ) FROM issues_repository; + """, + reverse_sql=migrations.RunSQL.noop, + ) + )