Resolve migration errors
Project description
django-migration-fixer
Problem
Maintain a linear migration history when conflicts occur as a result of changes made using different versions of the default branch.
Example
Branch: main
migrations
├── 0001_initial.py
├── 0002_auto_20210521_2328.py
Branch: feature/test-a
migrations
├── 0001_initial.py
├── 0002_auto_20210521_2328.py
├── 0003_auto_20210522_1128.py
Branch:feature/test-b
migrations
├── 0001_initial.py
├── 0002_auto_20210521_2328.py
├── 0003_auto_20210522_1228.py
Both feature/test-a
and feature/test-b
share the last migration on main
(0002_auto_20210521_2328.py
)
Once feature/test-a
is merged into main
you run into the problem of resolving migrations on feature/test-b
which was dependent on 0002_auto_20210521_2328.py
Branch: main
migrations
├── 0001_initial.py
├── 0002_auto_20210521_2328.py
├── 0003_auto_20210522_1128.py
Branch: feature/test-b
migrations
├── 0001_initial.py
├── 0002_auto_20210521_2328.py
├── 0003_auto_20210522_1128.py \___________________ Both dependent on 0002_auto_20210521_2328.py
├── 0003_auto_20210522_1228.py /
Error running makemigrations
CommandError: Conflicting migrations detected; multiple leaf nodes in the migration graph: (0003_auto_20210522_1128, 0003_auto_20210522_1228 in my_app).
To fix them run 'python manage.py makemigrations --merge'
Using the default --merge
option creates a new migration file which might not be desired.
Solution
django-migration-fixer
identifies changes between the default branch main
, and the feature branch feature/test-b
and maintains a linear dependency history as shown below:
Run
$ python manage.py makemigrations --fix
Branch: feature/test-b
migrations
├── 0001_initial.py
├── 0002_auto_20210521_2328.py
├── 0003_auto_20210522_1128.py
├── 0004_auto_20210522_1228.py
NOTE: This also works when there are conflicts detected on the default branch. i.e You can run
... makemigrations --fix
on themain
branch.
Assumptions
The final migration on the default branch would be used as the base for all subsequent migrations.
Installation
$ pip install django-migration-fixer
Add migration_fixer
to your INSTALLED_APPS
INSTALLED_APPS = [
...,
"migration_fixer",
...,
]
Usage
$ python manage.py makemigrations --fix
Specifying a different default branch name
Use:
$ python manage.py makemigrations -b master --fix
Features
- Resolves migration conflicts on both the default branch or feature/PR branches
- Supports numbered migration files i.e (
0001_....py
) - Supports non-numbered migration files i.e (
custom_migration.py
) - Re-index all migrations using the last migration on the default branch i.e
main
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for django-migration-fixer-0.0.2.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | df05a0a5e15e9e38f9897d81047f221f8497274392b6d5282392dc97a122a1d1 |
|
MD5 | 2193aa578bec5b62213e6c9ff613751e |
|
BLAKE2b-256 | 109cc08fe302ccf5aa333489024be5a84a26640e173cc1efaeb068b0e78cbeea |
Hashes for django_migration_fixer-0.0.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 47899bc29841f6cd541ed4db0435496fcef201d2faf9609e6eb39592d1c9c93b |
|
MD5 | 16a9c0c9f6df6d6f985b34d27751bded |
|
BLAKE2b-256 | e7a0d7ade8f081395d6e3f930f575dd3741e5a603baf9476c302261da3d30a52 |