Skip to content

Instantly share code, notes, and snippets.

@simion
Last active October 20, 2016 08:39
Show Gist options
  • Save simion/eca0426de2bec242135c72e0ee274dd4 to your computer and use it in GitHub Desktop.
Save simion/eca0426de2bec242135c72e0ee274dd4 to your computer and use it in GitHub Desktop.
Reset Django migrations (delete everything and create initial migrations)
#!/bin/sh
# this step is made only once by a single developer
# changes made by this script must be committed and pushed
if [[ `git status --porcelain` ]]; then
# working copy is not clean
echo "please commit or stash your changes"
exit
fi
# delete migrations
find . -path "*/migrations/*.py" -not -name "__init__.py" -delete
find . -path "*/migrations/*.pyc" -delete
./manage.py makemigrations
git status
echo "Migrations deleted and initial migrations created. Please commit the changes"
# git add .
# git commit -m "reset migrations"
# git push
#!/bin/sh
# every developer should merge the previous changes and run:
mysql -u<db_user> -p <db_pass> <db_name> -e 'DELETE FROM `django_migrations` where `id` > 0;'
# and
./manage.py migrate --fake
# done
# you should do this also on production server
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment