# Zero-Downtime Django Migrations

> Ship Django + PostgreSQL migrations without locking prod: timeouts, concurrent indexes, expand/contract, batched backfills.

Zero-Downtime Django Migrations is a free AI agent skill on Agensi by USMAN ASIF, in APIs & Backend. It loads into your AI agent through the Agensi MCP server, always in its latest approved version.

- Price: Free
- Creator: [USMAN ASIF](https://www.agensi.io/creators/usman-asif)
- Category: [APIs & Backend](https://www.agensi.io/skills/apis-backend)
- Uses: 2
- Version: 1.0
- Last updated: 2026-10-15
- Security: scan passed (2026-10-15); every new listing is also reviewed by a person
- Listing: https://www.agensi.io/skills/zero-downtime-django-migrations
- Tags: api, django, postgresql, database, devops

## About this skill

### Never take production down with a migration again

Migrations run before the new code rolls out, so for a few minutes old code talks to the new schema. This skill teaches your agent to write Django and PostgreSQL migrations that survive that window: no long locks, no table rewrites, nothing the running code still needs gets removed.

### How it helps

- **No surprise outages.** Every migration gets a lock timeout and a statement timeout, so it fails fast instead of blocking traffic.
- **Safe indexes and constraints.** Concurrent index creation, and NOT VALID then VALIDATE for new constraints.
- **Safe multi-release changes.** Expand, migrate, contract: split risky changes across releases so old and new code both keep working.
- **Safe backfills.** Batched data migrations that don't hold a transaction open on a hot table.
- **Fewer review debates.** A per-operation lock reference and checklists tell reviewers what is safe and what is not.

### What's inside

A short `SKILL.md` with the two golden rules and the migration toolkit pattern, plus 4 reference guides: Postgres locks, indexes, columns/keys/constraints, and data backfills and deployment.

### Use it when

Adding or changing columns, indexes, constraints or foreign keys, writing RunPython/RunSQL backfills, reviewing `makemigrations` output, or setting up migration safety in a new Django service.

## Known limitations

Requires PostgreSQL. Only works with the TimeoutAwareMigration base class. Does not support MySQL or SQLite migration syntax.

## How to use this skill

1. Connect your AI agent to Agensi once: add the MCP server https://mcp.agensi.io/mcp/auth and sign in with your Agensi account (OAuth, no API key). Steps for Claude, ChatGPT, Claude Code, Codex, Cursor, VS Code and other agents: https://www.agensi.io/docs/mcp-setup
2. Ask your agent: "Use the Zero-Downtime Django Migrations skill from Agensi" and describe your task.
3. Your agent loads the skill from Agensi when it needs it. Nothing is downloaded.

## Frequently asked questions

### How does this skill prevent database downtime during deployments?

This skill prevents the table-level locks and service outages often caused by standard Django migrations on high-traffic PostgreSQL databases by enforcing safe patterns like concurrent indexing and mandatory timeouts.

### Can I use this skill with databases other than PostgreSQL?

The skill is specifically optimized for Django environments using PostgreSQL; it is not compatible with MySQL, SQLite, or other database backends due to its reliance on Postgres-specific locking logic.

### What exactly is included in the toolkit?

You will receive a specialized toolkit including the `TimeoutAwareMigration` base class, custom concurrent operation overrides, and a dedicated linter to identify production hazards.

### Does this skill help with complex breaking changes like renaming or deleting fields?

The skill guides you through the 'expand-contract' pattern, which involves a multi-release process to ensure that your application code remains compatible with the database state at every step of the migration.

### Does this require changing how I run migrations in my CI/CD pipeline?

Yes, it integrates directly with standard Django migration commands, replacing risky default operations with safety-first alternatives like `AddIndexConcurrentlyWithRetry`.

### Why should I use this skill instead of just asking a general AI for migration help?

The skill identifies 'hidden' risks that generic AI prompts often miss, such as the 'one concurrent operation per file' rule and the necessity of two-step validation for foreign keys.

---

Source: [Agensi](https://www.agensi.io), the marketplace of skills for AI agents. Any MCP-compatible agent (Claude, ChatGPT, Claude Code, Codex, Cursor, VS Code and more) connects at https://mcp.agensi.io/mcp/auth and signs in with an Agensi account; setup for every agent: https://www.agensi.io/docs/mcp-setup. Append .md to any skill, guide or docs address on agensi.io for its markdown version.
