Skip to main content

Django Migrations Guardrail

Django Migrations Guardrail is a Django migration checker for catching schema drift, migration history problems, and model-to-database mismatches before they turn into broken deploys.

If you are looking for a Django package to verify migrations, check database sync, or add safer migration deploy checks, this package is built for that workflow.

It extends Django's normal migrate command with a --sync option:

python manage.py migrate --sync

That command enforces strict consistency by running safe pre-migration checks first. It halts if any discrepancies (or unapplied migrations) are found, applies migrations only if the history is perfectly clean, and then verifies the final database schema state.

  • Django system checks
  • migration files vs django_migrations
  • model fields vs database columns

Why Use It

django-migrations-guardrail helps when your Django app has:

  • migrations applied in code but not recorded in the database
  • migrations recorded in the database but missing on disk
  • schema drift caused by manual database edits
  • broken deploys after edited, deleted, or faked migrations
  • field definitions that no longer match real database columns

Background

This package is motivated by a common Django failure mode: the database schema, the django_migrations table, and migration files can drift apart after manual database edits, deleted migration files, edited old migrations, or faked migrations.

As discussed in this Django Forum thread, migration files should be treated as critical project code, not disposable generated files:

https://forum.djangoproject.com/t/database-out-of-sync-with-migrations/30358/7

django-migrations-guardrail helps detect those sync problems before they turn into confusing production errors.

Features

  • Adds python manage.py migrate --sync
  • Works as a Django migration checker before and after deploys
  • Runs pre-migration checks before applying migrations
  • Applies pending migrations only if preflight checks pass
  • Runs full database sync checks after migrations succeed
  • Runs Django's built-in system checks
  • Checks project migration files against the django_migrations table
  • Ignores third-party package migrations such as django_celery_beat, sessions, and token_blacklist
  • Detects migrations that exist in code but are not applied in the database
  • Detects migrations recorded in the database but missing from code
  • Supports squashed migrations through Django's replaces metadata
  • Detects inconsistent migration dependencies
  • Checks model fields against real database columns
  • Reports missing database tables
  • Reports fields missing from the database
  • Reports database columns that no longer exist in models
  • Helps detect Django schema drift during deployment
  • Writes an HTML report with --html-report
  • Can be installed from PyPI or directly from GitLab

Installation

Install from PyPI with pip:

python -m pip install django-migrations-guardrail

If your project uses uv, add it as a dependency:

uv add django-migrations-guardrail

Install from a Git checkout when testing an unreleased branch or tag:

python -m pip install "git+ssh://git@gitlab.decipherzone.com/divendra.pathak/django-migrations-gaurdrail.git@v0.1.1"

Or with uv:

uv add "django-migrations-guardrail @ git+ssh://git@gitlab.decipherzone.com/divendra.pathak/django-migrations-gaurdrail.git@v0.1.1"

Install from a local checkout while developing:

uv add --editable /path/to/django-migrations-guardrail

Or with pip:

python -m pip install -e /path/to/django-migrations-guardrail

Django Setup

Add the app to INSTALLED_APPS:

INSTALLED_APPS = [
    # ...
    "migration_guardrail",
]

Check that Django sees the custom option:

python manage.py migrate --help

You should see:

--sync

Usage

Use this before deployment or after pulling code changes:

python manage.py migrate --sync

This command acts as a strict consistency guardrail:

  • runs preflight checks to ensure your codebase and database are perfectly aligned
  • halts immediately if discrepancies or unapplied migrations are detected
  • applies migrations only if the environment is safe
  • runs full database schema reality checks after migration succeeds

If the preflight check fails (e.g., due to unapplied migrations or missing files), you must resolve the discrepancies (e.g., by running a standard migrate) before --sync will proceed. If everything succeeds, the package confirms your code, migration history, and database schema are completely aligned.

Use migration_guardrail_sync when you want the full check without applying migrations:

python manage.py migration_guardrail_sync

This command runs Django system checks, migration-history checks, and model vs database schema checks. It does not apply migrations.

HTML Reports

Write an HTML report after migrate --sync:

python manage.py migrate --sync --html-report

By default this creates:

migration_guardrail_report.html

Write the HTML report to a custom path:

python manage.py migrate --sync --html-report reports/migration_guardrail.html

Download the full sync report as HTML:

python manage.py migration_guardrail_sync --html-report reports/migration_sync.html

Package Names

Install/package name:

django-migrations-guardrail

Django app/import name:

"migration_guardrail"

Metadata

Release files for django-migrations-guardrail 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-migrations-guardrail 0.2.0
File Size Uploaded Provenance Actions
django_migrations_guardrail-0.2.0.tar.gz 12.5 kB With provenance Details for django_migrations_guardrail-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for django-migrations-guardrail 0.2.0
File Interpreter ABI Platform Actions
django_migrations_guardrail-0.2.0-py3-none-any.whl Python 3 none any Details for django_migrations_guardrail-0.2.0-py3-none-any.whl

Total release size: 25.3 kB

Release files / django_migrations_guardrail-0.2.0.tar.gz

Download URL django_migrations_guardrail-0.2.0.tar.gz
Size 12.5 kB
Tags Source
SHA-256 checksum
How to use checksums
46e11194b63ad357276c6937a838d5e43c70f6cca526df5394159ee2c93f6272
BLAKE2b-256 checksum
How to use checksums
4ec06b6a901181ac77c1108928fa975e5d03fed2cceac16dc6400d2b7ecc5318
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 29, 2026.

Transparency log

Release files / django_migrations_guardrail-0.2.0-py3-none-any.whl

Download URL django_migrations_guardrail-0.2.0-py3-none-any.whl
Size 12.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
88aee934f2a8b149fa5a1e43dff6c2e0532c216fc9e1f4e019b211df40bb75cb
BLAKE2b-256 checksum
How to use checksums
74be738224ca69d9e9690c454c9841972fc8635f234056b25e476f2d89bba1a6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 29, 2026.

Transparency log

Security for django-migrations-guardrail 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for django_migrations_guardrail-0.2.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 29, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page