I have an import script that runs a series of commands to get things from one Postgres database to another, both of which work with the same Django code base. For the most part, he uses. /manage.py loaddata to copy, but some objects require additional processing, and I use the Django objects.create () method in a user script to copy data. In this case, I specify the ID, i.e.
MyObject.objects.create(id = 2, title = 'foo')
As soon as the script is executed, I notice that Postgres SEQUENCE is wrong in the tables where I did objects.create (). I., it was 50 before import, and another 50 after, although the table now has 150 objects. This, of course, leads to errors when creating new objects, because it tries to use an existing ID (in all these tables, the identifier is simply a field for automatically increasing the number of vanilla). However, tables filled with. /manage.py loaddata, look normal.
I know that I can manually reset these tables with Django./manage.py sqlsequenreset, but I'm curious why the sequence seems to get out of impact in the first place. Does object.create () increase it? Can I ignore something obvious?
django postgresql
Krh
source share