I have an import script which runs a series of commands to get things from one Postgres DB to another, both running the same Django codebase. For the most part, it uses ./manage.py loaddata to copy over, but some objects require additional processing and I use Django's objects.create() method in a custom script to copy the data. When doing this, I specify the ID, i.e,
MyObject.objects.create(id = 2, title = 'foo')
Once the script is done, I'm noticing that the Postgres SEQUENCE is wrong on the tables where I did objects.create(). I.e., it was 50 before the import, and still 50 after, even though the table now has 150 objects. This, of course, leads to errors when creating new objects, since it tries to use an ID which already exists (On all these tables, the ID is just a vanilla auto-increment field). However, the tables which were filled via ./manage.py loaddata seem fine.
I'm aware that I can manually reset these tables with Django's ./manage.py sqlsequenreset, but I'm curious as to why the sequence seems to get out of whack in the first place. Does objects.create() not increment it? Am I overlooking something obvious?