Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django South migration history causing an integrity error

My south migration history table is causing integrity errors every time I try to run a new migration. Here is the error:

django.db.utils.IntegrityError: duplicate key value violates unique constraint "south_migrationhistory_pkey"
DETAIL:  Key (id)=(40) already exists.

So far, this is only happening locally. I have deleted the database and rebuilt a number of times, and each time all existing migrations run smoothly. But as soon as I create a new migration, I get this error again.

Migration 40 happens to be a third party migration (djangoratings), so I don't believe it is a problem with that migration file.

Any help would be greatly appreciated!

like image 440
JazzTpt Avatar asked Jan 14 '23 07:01

JazzTpt


1 Answers

How about

SELECT setval('south_migrationhistory_id_seq', (SELECT MAX(id) FROM south_migrationhistory));

That worked for me.

You probably should do a pg_dump beforehand, just in case it all goes wrong.

I'm using postgres, you might need to use a slightly different command to update your database sequence for other databases.

like image 165
Brendan Quinn Avatar answered Jan 16 '23 20:01

Brendan Quinn