shlogg · Early preview
Shakhzhakhan Maxudbek @xinitd

Resetting Autoincrement Sequences In Django After Deletion

After deletion, Django models' autoincrement IDs don't reset. Use `python manage.py sqlsequencereset <app_name>` to generate SQL for resetting sequences. Run it with `dbshell` or in PostgreSQL's psql shell with `ALTER SEQUENCE`.

After deletion entries in your model relational database management systems not resetting autoincrementations and continue counting old IDs sequences. For start counting entries from 1 again you need reset sequence manually.
Django's autogenerated manage.py script have argument named "sqlsequencereset". It helps to reset autoincrement sequences for IDs in Django application after all instances in model are deleted. Documentation say:

django-admin sqlsequencereset app_label [app_label ...]
Prints the SQL statements for resetting sequences for the given app name(s).
Sequences are indexes used b...