django-pg-migration-tools
Tools for making Django migrations safer and more scalable.
What it is and what it does
django-pg-migration-tools is a Django package that wraps PostgreSQL-specific migration operations to make schema changes safer in production environments. It provides drop-in replacements for standard Django migration operations—adding/removing constraints, indexes, and foreign keys—that use PostgreSQL's non-blocking techniques (like concurrent index creation) and timeout controls to prevent migrations from locking tables and blocking application traffic.
The package includes management commands to run migrations with configurable statement and lock timeouts, and context managers to apply timeouts to arbitrary database operations. It's designed for teams running Django on PostgreSQL who need to perform schema changes on live databases without downtime or long-running locks. The codebase is actively maintained, supports modern Python versions, and carries no runtime dependencies beyond Django itself.
Use it for:
- Add indexes to large production tables without blocking reads and writes during the migration window.
- Add or remove unique and check constraints safely using PostgreSQL's non-blocking constraint creation.
- Set columns to NOT NULL on populated tables by validating data before applying the constraint.
- Run all migrations with automatic statement and lock timeouts to prevent runaway queries from blocking the application.
- Add foreign keys to existing tables with validation and optional constraint deferral.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Provides safer, production-ready Django migration operations for PostgreSQL, including concurrent index management, constraint handling, and timeout controls to prevent long-running migrations from blocking production databases.
Yes, if you run Django on PostgreSQL and perform schema migrations on live databases. The package directly addresses a real production pain point—long-running migrations that lock tables—and is actively maintained with no external dependencies. The alpha status reflects early releases, but the core operations are straightforward and well-documented. Install if you need safer schema changes; skip if you use a different database backend or have no production migration concerns.
Install
django-pg-migration-tools on PyPI
pip
pip install django-pg-migration-toolsuv
uv add django-pg-migration-toolspoetry
poetry add django-pg-migration-toolsInstalling django-pg-migration-tools
Before you install
Low friction installation with no runtime dependencies. Actively maintained as of 2026-02-27 with recent releases. Supports current Python versions (3.10 through 3.14).
License in practice
BSD 3-Clause License permits commercial and private use with minimal restrictions; you may modify and distribute freely provided you retain copyright notices and disclaimers.
Quickstart
pip install django-pg-migration-tools
from django_pg_migration_tools.operations import SaferAddIndexConcurrently
class Migration(migrations.Migration):
operations = [
SaferAddIndexConcurrently(
model_name='mymodel',
index=models.Index(fields=['field_name'])
)
]
Requires Django and PostgreSQL; operations are PostgreSQL-specific and will not work with other database backends.
Verify before relying
- Minimum Django version requirement not specified in fact sheet.
- Whether all operations are backward-compatible with existing migration files.
- Performance impact of safer operations compared to standard Django migrations.
Package facts
| License | BSD 3-Clause License Copyright (c) 2024, Kraken Technologies Limited Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following… (full text in the JSON record) (permissive) |
| Python support | supports the current Python release (>=3.10) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | none |
| Maintenance | actively maintained — 168 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 76,180/month — #14,650 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: django_pg_migration_tools-0.1.26-py3-none-any.whl
Tags
More Database packages
psycopg2-binary is a PostgreSQL database…
copyleft · top 1,000 on PyPI
redisPython client library for connecting to and…
permissive · top 1,000 on PyPI
ydbYDB Python SDK is the official client library…
permissive · top 1,000 on PyPI
snowflake-connector-pythonConnects Python applications to Snowflake data…
permissive · top 1,000 on PyPI
sqlparsesqlparse tokenizes SQL text into a tree of…
permissive · top 1,000 on PyPI
dbt-adaptersProvides base adapter protocols and shared…
permissive · top 1,000 on PyPI
django-pg-zero-downtime-migrationsProvides a Django database backend for…
permissive · top 15,000 on PyPI
django-postgres-extraExtends Django's ORM to expose…
permissive · top 15,000 on PyPI
django-pgmigratePrevents migration downtime by detecting and…
permissive · top 5,000 on PyPI
squawk-cliLinter that analyzes PostgreSQL migrations and…
permissive · top 15,000 on PyPI
django-pglockProvides Postgres advisory locks, table locks,…
permissive · top 5,000 on PyPI
django-safemigrateAdds a safemigrate command to Django that…
permissive · top 15,000 on PyPI
django-pgviews-reduxAdds first-class PostgreSQL view support to…
unclear · top 15,000 on PyPI
migramigra compares PostgreSQL database schemas and…
permissive · top 15,000 on PyPI
yoyo-migrationsYoyo-migrations is a database schema migration…
permissive · top 15,000 on PyPI
django-syzygyAutomates Django database migration deployment…
permissive · top 15,000 on PyPI