--- id: django-safemigrate version: "6.0" license: MIT license_treatment: permissive maintenance: aging --- # django-safemigrate — Safely run migrations before deployment License: permissive · Maintenance: aging · Downloads: 97.6K/mo ## What it is and what it does django-safemigrate is a Django extension that adds a safemigrate command to control when migrations run relative to code deployment. It lets you mark each migration as safe to run before deployment (e.g., adding a column), after deployment (e.g., removing a column), or always safe. When you run safemigrate, only migrations marked as safe for the current deployment phase will execute; if an unsafe migration blocks a safe one, the command fails rather than proceeding. The package solves a common deployment problem: running the wrong migrations at the wrong time can cause downtime or data loss. By explicitly marking migrations and enforcing their order, it prevents accidental unsafe runs. It supports a delay mechanism for after-deploy migrations, nonstrict mode for development, and integrates with pre-commit to catch unmarked migrations before they reach version control. The normal migrate command continues to work unchanged. Use it for: - Mark a migration that adds a new column as Safe.before_deploy so it runs during the pre-deployment phase, before new code is live. - Mark a migration that removes a deprecated column as Safe.after_deploy so it only runs after the code no longer references it. - Use Safe.after_deploy(delay=timedelta(days=7)) to defer a destructive migration for a week, reducing risk of rollback. - Enable nonstrict mode in development to allow migrations to accumulate between developers without blocking the safemigrate command. - Use the pre-commit hook to enforce that all migrations in a repository are explicitly marked with a safe value. ## Worth the install? AI-flagged interpretation of the facts above — verify before relying. Adds a safemigrate command to Django that selectively runs migrations marked as safe before deployment, blocking unsafe ones and preventing deployment-order errors. Yes, if you deploy Django applications and want to reduce deployment-order migration errors. The low install friction and permissive license make it a safe add. However, the aging maintenance status (437 days since last release) means you should verify compatibility with your Django version before relying on it in production. ## Install pip install django-safemigrate uv add django-safemigrate poetry add django-safemigrate ## Installing django-safemigrate Before you install: Low install friction with a single runtime dependency on django. Maintenance status is aging—last release was 437 days ago, though the repository remains active and the package has been stable since its first release in 2019. License in practice: MIT license is permissive; you can use, modify, and distribute this package freely with minimal restrictions. Quickstart: pip install django-safemigrate # In settings.py, add to INSTALLED_APPS: INSTALLED_APPS = [ "django_safemigrate", ] # In a migration file: from django_safemigrate import Safe class Migration(migrations.Migration): safe = Safe.before_deploy Requires Python 3.9 or later and Django as a runtime dependency. Verify before relying: - Whether the aging maintenance status (437 days since last release) affects compatibility with recent Django versions. - Real-world effectiveness of the pre-commit hook in preventing unmarked migrations from reaching production. ## Package facts - License: MIT (permissive) - Python support: supports_current - Install friction: low - Maintenance: aging - Downloads: 97.6K/month (top 15,000 on PyPI) - Known vulnerabilities: none known ## Tags django migration safety, pre-deployment migrations, django safemigrate command, safe database migrations, deployment migration control, django migration blocking, migration timing management, django-extension, deployment-safety, database-migrations [View on SkillFed](https://skillfed.io/packages/django-safemigrate) · [View on PyPI](https://pypi.org/project/django-safemigrate/)