django 1.7 migrations -- how do I clear all migrations and start over from scratch?
So the step-by-step plan I outlined in my question does work, but instead of deleting rows from the south_migrationhistory
database table, I had to delete rows from the django_migrations
database table.
The command is: DELETE FROM django_migrations WHERE app='my_app'
Once this is done, you will be able to re-run your migrations from scratch.
I just wanted to put all the steps into a command format:
NOTE: The commands below are pretty destructive, it is a means to start from scratch
as the OP asked.
After a comment from mikeb
I thought to add this line:
PRE - CHECK WHAT FILES YOU WOULD DELETE
find . -path "*migrations*" -name "*.py" -not -path "*__init__*"
Then, adjust the command in step 1
to one that works for your dev environment.
- remove all the migrations from all the apps:
find . -path "*migrations*" -name "*.py" -not -path "*__init__*" -exec rm {} \; # make sure to be in your projects path
- recreate the whole database:
sudo -u postgres bash -c "psql -c \"DROP DATABASE rootedin;\""
sudo -u postgres bash -c "psql -c \"CREATE DATABASE rootedin;\""
sudo -u postgres bash -c "psql -c \"GRANT ALL PRIVILEGES ON DATABASE rootedin to vagrant;\"" # vagrant is my current user
- get your db up to date:
python3 manage.py makemigrations
python3 manage.py migrate