I have a set up (Django 1.11) with several apps including OOK, EEK, and others irrelevant ones. I want to delete all the data for OOK while leaving EEK (and the rest) untouched. Ideally, I want all the primary keys to be reset as well so the first new OOK model will get 1 and so on…
Is this possible?
All I can find is reset
and sqlclear
which are both deprecated. flush
removed all data from the database and thus not what I want
I do release that this is an odd thing to do, but this is the hand given to me…
You can achieve this behaviour dropping all the tables of that <app>
and then migrating only that <app>
. That way you'll reset the tables of the <app>
. In django 1.7+
you can do:
$ python manage.py migrate OOK zero //This command unapply your migrations
$ python manage.py migrate OOK
https://docs.djangoproject.com/en/2.0/ref/django-admin/#django-admin-migrate
If you are allowed to replace the db, you could export the data you need to a fixture, then do some clever text processing in the json that is in there, say by finding all ID
fields and replacing them from 1. Then reimport the result into a clean db?
The id
s are autoincremented by postgresql, according to this answer you can reset the index sequence, but not even sure it can go back to 1.
But really what's the point of resetting the indexes?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With