Skip to main content
Packaging: poetry Code style: black Build status Code coverage PyPi version Downloads

If you are in a complex Django project, sometimes you will find yourself switching between multiple branches, some of which can add a number of database migrations. Before switching back to master you will have to unapply all migrations that are specific to the current branch. In order to unapply these, you will have to enter the migration that comes right before the first migration of the current branch. If two or more apps are involved, you will have to do that for each one of them.

If you leave your migration names unchanged, inferring the name of the right migration to target is not too difficult, because they are prefixed by default with a sequential number. Django also helps, being smart enough to let you use an unambiguous prefix of any migration name. Add a merge migration and the numbers will no longer be so obvious. Or if you have renamed your migration files to drop the sequential numbers you will have to do the search manually.

With django-unmigrate you can speed up the process.

Usage

Add django_unmigrate to your INSTALLED_APPS. This is required to make the unmigrate management command available.

Then, while standing on any branch, you will be able to use:

python manage.py unmigrate master

Or if it’s going to be master anyways, this will suffice:

python manage.py unmigrate

And that’s it!

A little deeper

Ok, you can do more than that.

Do you need to unapply your migrations from the same branch, a few commits behind? Here’s how:

python manage.py unmigrate HEAD~12
python manage.py unmigrate b13553d
python manage.py unmigrate v1.33.7

Or if you only want to see the target migrations, do:

python manage.py unmigrate --dry-run

Finally, if you just want to play with the app with no actual modifications in the database, go ahead and unapply your migrations with fake. Just don’t forget to apply them again at the end:

python manage.py unmigrate --fake
python manage.py migrate --fake

Contributing

  • Join the discussion at https://github.com/lorinkoz/django-unmigrate/discussions.

  • PRs are welcome! If you have questions or comments, please use the link above.

  • To run the test suite run make or make coverage. The tests for this project live inside a small django project called dunm_sandbox. Beware! This package uses Git to function, therefore, the tests expect a number of commit hashes inside this repository to be present and remain stable in order to function. See this meta file for further details.

Metadata

Release files for django-unmigrate 0.3.1

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-unmigrate 0.3.1
File Size Uploaded Provenance
django-unmigrate-0.3.1.tar.gz 6.4 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for django-unmigrate 0.3.1
File Interpreter ABI Platform
django_unmigrate-0.3.1-py3-none-any.whl Python 3 none any Details

Total release size: 13.3 kB

Release files / django-unmigrate-0.3.1.tar.gz

Download URL django-unmigrate-0.3.1.tar.gz
Size 6.4 kB
Tags Source
SHA-256 checksum
How to use checksums
4ec10563a0dc51c43870d03da89b5d8312e5d6edc2943d2353db9ed0e843c955
BLAKE2b-256 checksum
How to use checksums
92f7b00c7611ca4747aeb639a3c635f495c7c7262ddc7e5ec823e6679ea2e3ca
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

Release files / django_unmigrate-0.3.1-py3-none-any.whl

Download URL django_unmigrate-0.3.1-py3-none-any.whl
Size 6.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
996542a7d8d984eb40846fd53346a8546c92f161b17f61b73661e6a5b56e3bd2
BLAKE2b-256 checksum
How to use checksums
0cab67f92f459c2850f7a4689e5720dc0aed1042a14b5b24f1cf692ff1067bc0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

Security for django-unmigrate 0.3.1

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.

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