I created a user import view (with Django's User model) for a new Wagtail app, which works well. I did a few tests, and ended up with IDs for my test users in the range of 140-150 on my development machine. Afterwards, I transferred the DB to a test machine.
When I tried to create a new user via the Wagtail admin interface on the test machine, a unique constraint violation for auth_user_pkey
was returned. But the offending new ID was close to the highest existing ID, so after three more tries, I arrived at an unused ID and was able to create the new account.
What is going on here? Why does Wagtail try to (re-)use existing IDs, and how can I prevent the issue?
Depending on the details of how you transferred the database, this is probably to do with how your Postgres DB tracked the sequence used to get the primary key / ids. So not something the Wagtail layer controls directly.