Skip to main content

Django reset migrations with `zeromigrations` command with backup feature

Project description

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:

  1. migrate --fake {app_name} zero for each app.

  2. Remove old migration files, as new migrations is going to be generated.

  3. makemigrations to generate initial migration file.

  4. 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

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_zeromigrations-0.1.6-py3-none-any.whl (11.0 kB view details)

Uploaded Python 3

File details

Details for the file django_zeromigrations-0.1.6-py3-none-any.whl.

File metadata

File hashes

Hashes for django_zeromigrations-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 78e5951f529775e40f84c2fbad018997b9ff5674810f31beba05b2524eff62ce
MD5 7122765dec76f61a9698fdfe741d8ee0
BLAKE2b-256 368a04cbf70444d1641260b9a8200295e80175999ff67766ed645f385a02089c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page