1

I've migrated a DB from a Django App from SQLite to Postgres. When I enter new data on the admin view I get an error message that the primary key already exists.

duplicate key value violates unique constraint

I tried to resync the sequences in postgres using the following command, which generates the required SQL script.

python manage.py sqlsequencereset app | python manage.py dbshell

I still get the same error as before.

How can I check whether the sequence was resynced correctly and the next id is set to MAX(id)+1 or so?

Astik Anand
  • 12,757
  • 9
  • 41
  • 51
ipa
  • 1,496
  • 1
  • 17
  • 36
  • I saw this post previously, but it didn't work with sqlsequencereset. Apparently this command produces SQL that doesn't work with my postgres version (11.3) python manage.py sqlsequencereset app Therefore I had to run it manually with SELECT setval('tablename_id_seq', (SELECT MAX(id) FROM tablename)+1) one after the other – ipa Aug 05 '19 at 09:04

0 Answers0