Sample Header Ad - 728x90

Reset all sequences so that they continue after max(id) + 1?

1 vote
1 answer
1998 views
It looks like I messed up a database migration and while all sequences are there, they would start at 1, which triggers errors like: > django.db.utils.IntegrityError: duplicate key value violates unique > constraint "django_admin_log_pkey" DETAIL: Key (id)=(2) already > exists. Is there a query/script I could run that would run across all tables in the database, look at any columns tied to a sequence and reset those sequences to max(column) + 1? Using PostgreSQL v11.
Asked by d33tah (429 rep)
Sep 3, 2019, 06:41 AM
Last activity: Jan 19, 2025, 06:02 AM