skillfed

django-test-migrations

Test django schema and data migrations, including ordering

django-test-migrations v1.6.0 658.2K downloads/30d#5,470 on PyPI573
Permissive license MIT Active released

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

uv

uv add django-test-migrations

poetry

poetry add django-test-migrations

Installing 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

Development Status :: 5 - Production/StableFramework :: DjangoFramework :: Django :: 3.2Framework :: Django :: 4.1Framework :: Django :: 4.2Framework :: Django :: 5.0Framework :: Django :: 5.1Framework :: Django :: 5.2Framework :: Django :: 6.0Framework :: Django :: 6.1Intended Audience :: DevelopersOperating System :: OS IndependentTopic :: Internet :: WWW/HTTPTopic :: Internet :: WWW/HTTP :: Dynamic ContentTopic :: Software Development :: Libraries :: Python Modules

Tags

django migration testingtest django migrationsmigration rollback testingdjango schema migration testsmigration order validationdjango data migration testingpytest django migrations
django-testingmigration-validationpytest-plugin

More Python Modules packages