django-safemigrate
Safely run migrations before deployment
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 on this page — 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
django-safemigrate on PyPI
pip
pip install django-safemigrateuv
uv add django-safemigratepoetry
poetry add django-safemigrateInstalling 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 the current Python release (>=3.9) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 1 — django |
| Maintenance | aging — 437 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 97,551/month — #13,147 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: django_safemigrate-6.0-py3-none-any.whl
Tags
More Quality Assurance packages
Coverage.py measures which lines of Python code…
permissive · top 1,000 on PyPI
ruffRuff is a Python linter and code formatter…
permissive · top 1,000 on PyPI
pexpectPexpect spawns and controls interactive console…
permissive · top 1,000 on PyPI
blackBlack reformats Python source code to a…
permissive · top 1,000 on PyPI
pytest-xdistpytest-xdist distributes pytest tests across…
permissive · top 1,000 on PyPI
cfn-lintValidates AWS CloudFormation templates in YAML…
permissive · top 1,000 on PyPI
django-pgmigratePrevents migration downtime by detecting and…
permissive · top 5,000 on PyPI
django-syzygyAutomates Django database migration deployment…
permissive · top 15,000 on PyPI
django-linear-migrationsEnforces linear migration history in Django…
permissive · top 5,000 on PyPI
django-pg-zero-downtime-migrationsProvides a Django database backend for…
permissive · top 15,000 on PyPI
django-pg-migration-toolsProvides safer, production-ready Django…
permissive · top 15,000 on PyPI
django-add-default-valueProvides a Django migration operation to set…
permissive · top 15,000 on PyPI
django-test-migrationsTests Django schema and data migrations,…
permissive · top 15,000 on PyPI
Flask-MigrateFlask-Migrate handles SQLAlchemy database…
permissive · top 5,000 on PyPI
django-migration-linterAnalyzes Django migrations to detect…
permissive · top 5,000 on PyPI