4

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!

Chris Travers
  • 25,424
  • 6
  • 65
  • 182
JazzTpt
  • 93
  • 8
  • 1
    update djangoratings. They have fixed the error in the latest release – karthikr May 23 '13 at 16:00
  • I'm already at the latest djangoratings, 0.3.7. According to Andrew Godwin, this can happen if you have ever manually edited the south_migrationhistory table in your database. Lesson learned. – JazzTpt May 23 '13 at 16:48

1 Answers1

9

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.

Brendan Quinn
  • 2,059
  • 1
  • 19
  • 22