Skip to content

Instantly share code, notes, and snippets.

@TobeTek
Created November 9, 2023 20:51
Show Gist options
  • Save TobeTek/ede692abbe13034ab2be7763583f4e13 to your computer and use it in GitHub Desktop.
Save TobeTek/ede692abbe13034ab2be7763583f4e13 to your computer and use it in GitHub Desktop.
Delete all migrations in a Django project
#!/bin/bash
# Written by ChatGPT with some human help 🙂
# Loop through all apps in your project
for app in $(python manage.py showmigrations -l | grep -v '^\[ \]'); do
echo "Deleting migration files for $app..."
# Delete all migration files except __init__.py
find "$app/migrations" -name '00*.py' -not -name '__init__.py' -exec rm {} \;
echo "Migrations deleted for $app."
done
echo "All migration files deleted."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment