django-test-migrations
Test django schema and data migrations, including ordering
What it is and what it does
django-test-migrations is a testing library that lets you write automated tests for Django database migrations. It provides a Migrator class to apply migrations in isolation, inspect database state before and after, and verify that data is preserved correctly. It also validates migration ordering and dependencies, and detects rollback issues. The library integrates with pytest (via fixtures and markers) and unittest (via a base test case), and supports factory_boy for creating test data.
You use it by applying an initial migration to set up a before-state, then applying the migration you want to test, then asserting on the resulting model structure and data. This catches bugs in complex schema or data transformations that unit tests alone won't catch. It's particularly useful when migrations modify existing data, add constraints, or change relationships—situations where silent data corruption is a real risk.
Use it for:
- Verify that a data migration correctly transforms existing records without loss or corruption.
- Test that a schema migration can be safely rolled back and re-applied without errors.
- Validate that all migrations in an app are in the correct order with correct dependencies.
- Ensure a new field migration applies the correct default values to existing rows.
- Confirm that a migration removing a column doesn't break dependent migrations.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Tests Django schema and data migrations, including forward/backward execution, ordering validation, and migration dependencies.
Yes. If you maintain Django projects with non-trivial migrations (data transformations, schema changes, rollbacks), this package is worth installing. It has low install friction, active maintenance, no known vulnerabilities, a permissive license, and solves a real problem—catching migration bugs before production. Start with it if you're already using pytest or unittest.
Install
django-test-migrations on PyPI
pip
pip install django-test-migrationsuv
uv add django-test-migrationspoetry
poetry add django-test-migrationsInstalling django-test-migrations
Before you install
Low friction: pure Python wheel with a single runtime dependency (typing-extensions). Active maintenance with a release 9 days ago and 573 repository stars.
License in practice
MIT license permits unrestricted use, modification, and distribution in both open-source and proprietary projects.
Quickstart
pip install django-test-migrations
from django_test_migrations.migrator import Migrator
migrator = Migrator(database='default')
old_state = migrator.apply_initial_migration(('app_name', '0001_initial'))
new_state = migrator.apply_tested_migration(('app_name', '0002_next'))
migrator.reset()
Requires Python 3.10 or later and a Django project with configured migrations (3.2, 4.1, 4.2, 5.0 officially supported; other versions likely work).
Verify before relying
- Whether all advertised Django versions (3.2–6.1) are equally well-tested or if some are less stable than others.
- Performance characteristics when testing large numbers of migrations or complex schema changes.
Package facts
| License | MIT (permissive) |
| Python support | supports the current Python release (<4.0,>=3.10) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 1 — typing-extensions |
| Maintenance | actively maintained — 9 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 658,190/month — #5,470 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: django_test_migrations-1.6.0-py3-none-any.whl
Keywords: django, django-migrations, django-orm, django-tests, migrations, orm, pytest, pytest-plugin, sql, test, tests
Tags
More Python Modules packages
Converts domain names between Unicode and…
permissive · top 100 on PyPI
setuptoolsSetuptools is a Python build backend and…
permissive · top 100 on PyPI
PyYAMLPyYAML parses and emits YAML 1.1 data format,…
permissive · top 100 on PyPI
pydanticPydantic validates Python data structures…
permissive · top 100 on PyPI
annotated-typesProvides reusable metadata objects for use with…
permissive · top 100 on PyPI
typing-inspectionProvides runtime tools to inspect and…
permissive · top 100 on PyPI
django-migration-linterAnalyzes Django migrations to detect…
permissive · top 5,000 on PyPI
pytest-alembicA pytest plugin that runs built-in and custom…
permissive · top 5,000 on PyPI
peewee-migratePeewee Migrate provides a command-line and…
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-safemigrateAdds a safemigrate command to Django that…
permissive · top 15,000 on PyPI
sqlalchemy-migrateProvides database schema migration management…
permissive · top 15,000 on PyPI
migramigra compares PostgreSQL database schemas and…
permissive · top 15,000 on PyPI
django-syzygyAutomates Django database migration deployment…
permissive · top 15,000 on PyPI