Skip to main content

Django migration linter

Detect backward incompatible migrations for your Django project. It will save you time by making sure migrations will not break with a older codebase.

PyPI GitHub_Stars

Quick installation

pip install django-migration-linter

And add the migration linter to your INSTALLED_APPS:

INSTALLED_APPS = [
    ...,
    "django_migration_linter",
    ...,
]

Optionally, add a configuration:

MIGRATION_LINTER_OPTIONS = {
    ...
}

For details about configuration options, checkout Usage.

Usage example

$ python manage.py lintmigrations

(app_add_not_null_column, 0001_create_table)... OK
(app_add_not_null_column, 0002_add_new_not_null_field)... ERR
        NOT NULL constraint on columns
(app_drop_table, 0001_initial)... OK
(app_drop_table, 0002_delete_a)... ERR
        DROPPING table
(app_ignore_migration, 0001_initial)... OK
(app_ignore_migration, 0002_ignore_migration)... IGNORE
(app_rename_table, 0001_initial)... OK
(app_rename_table, 0002_auto_20190414_1500)... ERR
        RENAMING tables

*** Summary ***
Valid migrations: 4/8
Erroneous migrations: 3/8
Migrations with warnings: 0/8
Ignored migrations: 1/8

The linter analysed all migrations from the Django project. It found 3 migrations that are doing backward incompatible operations and 1 that is explicitly ignored. The list of incompatibilities that the linter analyses can be found at docs/incompatibilities.md.

More advanced usages of the linter and options can be found at docs/usage.md.

Integration

One can either integrate the linter in the CI using its lintmigrations command, or detect incompatibilities during generation of migrations with

$ python manage.py makemigrations --lint

Migrations for 'app_correct':
  tests/test_project/app_correct/migrations/0003_a_column.py
    - Add field column to a
Linting for 'app_correct':
(app_correct, 0003_a_column)... ERR
        NOT NULL constraint on columns

The migration linter detected that this migration is not backward compatible.
- If you keep the migration, you will want to fix the issue or ignore the migration.
- By default, the newly created migration file will be deleted.
Do you want to keep the migration? [y/N] n
Deleted tests/test_project/app_correct/migrations/0003_a_column.py

The linter found that the newly created migration is not backward compatible and deleted the file after confirmation. This behaviour can be the default of the makemigrations command through the MIGRATION_LINTER_OVERRIDE_MAKEMIGRATIONS Django setting. Find out more about the makemigrations command at docs/makemigrations.md.

More information

Please find more documentation in the docs/ folder.

Some implementation details can be found in the ./docs/internals/ folder.

Blog post

They talk about the linter

  • django-test-migrations - Test django schema and data migrations, including migrations' order and best practices.

License

django-migration-linter is released under the Apache 2.0 License.

Maintained by David.

Created originally at 3YOURMIND.

Metadata

Release files for django-migration-linter 7.0.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-migration-linter 7.0.0
File Size Uploaded Provenance Actions
django_migration_linter-7.0.0.tar.gz 48.3 kB Without provenance Details for django_migration_linter-7.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for django-migration-linter 7.0.0
File Interpreter ABI Platform Actions
django_migration_linter-7.0.0-py3-none-any.whl Python 3 none any Details for django_migration_linter-7.0.0-py3-none-any.whl

Total release size: 76.2 kB

Release files / django_migration_linter-7.0.0.tar.gz

Download URL django_migration_linter-7.0.0.tar.gz
Size 48.3 kB
Tags Source
SHA-256 checksum
How to use checksums
e659aac2fc5f7241bc4e5a08e80eb764435da9f7cc7d1269bd84222f5550ba22
BLAKE2b-256 checksum
How to use checksums
21a5e422badd802022c9e0743494a3818b10644219bac5d016bbb3c654f55745
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.6

Release files / django_migration_linter-7.0.0-py3-none-any.whl

Download URL django_migration_linter-7.0.0-py3-none-any.whl
Size 28.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
62e9beb8255cf23a01d36dfd473f49445bcde3aed99582b66c76a3821853f154
BLAKE2b-256 checksum
How to use checksums
728e244479c37322fe5f457af246e75e033e381e95bdd8d22d85657b59dafa1a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.6

Security for django-migration-linter 7.0.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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

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

7.0.0 This release

2 release files No 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