Django Zero Migrations (Reset Migrations)
As the project grows up, the number of migration files increases over time. As a result, running them can consume a lot of time, specifically when you are running your tests.
zeromigrations is a command to reset migration files. It basically runs 4 commands:
migrate --fake {app_name} zero for each app.
Remove old migration files, as new migrations is going to be generated.
makemigrations to generate initial migration file.
migrate --fake-initial to fake generated initial files.
But besides that, this command can make a backup to restore in case of any failure.
Note that migrate --fake command only runs for your own apps and django apps like contenttype and third-party apps are excluded.
Installation
First install the package:
pip3 install django-zeromigrations
Then add it to your INSTALLED_APPS:
INSTALLED_APPS = [
...
"zero_migrations"
]
Usage
First, run the command:
python manage.py zeromigrations --backup-path=<YOUR_PATH>
I suggest to make a backups from both your migrations and django_migrations table (just in case).
1- make backup
2- restore last backup
3- just proceed
If you choose 1- make backup, it would make a backup then zero migrations.
If you choose 2- restore last backup, it tries to restore the latest backup that can be found. If not backup found, it would raise an error.
If you choose 3- just proceed, it assumes that you already have your own backup and start setting migrations zero.
Options
--backup-path: The absolute path of the dir that you want to store backups in. It should have –backup-path=<PATH> format. The default path is inside of zeromigrations app dir.
--use-fake-zero: By default, deleting migrations records from DB happens directly using ORM. With this flag, you can set to use python3 manage.py migrate app –fake zero (note that it has performance issue).
Metadata
Release files for django-zeromigrations 0.3.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| django_zeromigrations-0.3.2-py3-none-any.whl | Python 3 | none | any | Details for django_zeromigrations-0.3.2-py3-none-any.whl |
Release files / django_zeromigrations-0.3.2-py3-none-any.whl
| Download URL | django_zeromigrations-0.3.2-py3-none-any.whl |
|---|---|
| Size | 11.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
70bb353312909a120abd06b5ad71b9f36c8f89f954b11a073ff9f98785e8ec18
|
|
BLAKE2b-256 checksum How to use checksums |
9eeaf8653df4474e4e5773ccd090edec9377f916244023355cf25438ea20bb85
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.8.10
|
Security for django-zeromigrations 0.3.2
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.