Django South migration history causing integrity error

My south migration history table causes integrity errors every time I try to start 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. 

While this happens only locally. I deleted the database and rebuilt it several times, and each time all existing migrations are performed smoothly. But as soon as I create a new migration, I get this error again.

Migration 40 is a third party migration (djangoratings), so I don't think this is a problem with this migration file.

Any help would be greatly appreciated!

+4
source share
1 answer

What about

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

It worked for me.

You should probably do pg_dump in advance, just in case everything goes wrong.

I use postgres, you may need a slightly different command to update your database for other databases.

+9
source

Source: https://habr.com/ru/post/1482421/


All Articles