skillfed

django-safemigrate

Safely run migrations before deployment

django-safemigrate v6.0 97.6K downloads/30d#13,147 on PyPI96
Permissive license MIT AGING released

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-safemigrate

uv

uv add django-safemigrate

poetry

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 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

django migration safetypre-deployment migrationsdjango safemigrate commandsafe database migrationsdeployment migration controldjango migration blockingmigration timing management
django-extensiondeployment-safetydatabase-migrations

More Quality Assurance packages