django undo migration code example

Example 1: delete all migrations django

find . -path "*/migrations/*.py" -not -name "__init__.py" -delete
find . -path "*/migrations/*.pyc"  -delete

Example 2: how to undo makemigrations django

# The migration you want to undo is 0011_last_migration
# The migration right before it is 0010_previous_migration 
python manage.py migrate my_app 0010_previous_migration 

# Then you could delete the migration that you don't need (0011_last_migration) in the migration folder 

# list all migration names like this
python manage.py showmigrations my_app

Example 3: how to delete migrations in django

python3 manage.py rm -r name/migrations

Example 4: revert a migration django

python manage.py migrate <your-app> <migration number>
# eg
python manage.py migrate my_app 0001