Created
July 21, 2025 08:56
-
-
Save Afeez1131/8155c52c756e74f164fe7213edfc4546 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import glob | |
def delete_migrations(app_name): | |
# Get the path to the migrations folder of the app | |
migrations_path = os.path.join(app_name, 'migrations') | |
# Check if the migrations folder exists | |
if os.path.exists(migrations_path): | |
# Find all migration files (except __init__.py) in the migrations folder | |
migration_files = glob.glob(os.path.join(migrations_path, '*.py')) | |
migration_files += glob.glob(os.path.join(migrations_path, '*.pyc')) | |
# Loop through and delete each file (except __init__.py) | |
for migration_file in migration_files: | |
if os.path.basename(migration_file) != '__init__.py': | |
os.remove(migration_file) | |
print(f"Deleted: {migration_file}") | |
print("All migrations deleted successfully.") | |
else: | |
print(f"The app '{app_name}' does not have a migrations directory.") | |
if __name__ == "__main__": | |
app_name = input("Enter the Django app names (seperated by ',' for multiple at once): ") | |
app_name_list = app_name.split(',') | |
for app in app_name_list: | |
delete_migrations(app.lstrip().rstrip()) | |
# Run this script to delete all migration files in the migrations folder of the specified Django app(s). |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment