JazzTpt
JazzTpt

Reputation: 101

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!

Upvotes: 4

Views: 1072

Answers (1)

Brendan Quinn
Brendan Quinn

Reputation: 2249

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.

Upvotes: 9

Related Questions