https://github.com/tj-django/django-migration-fixer
Resolve multiple leaf nodes error running django migrations.
https://github.com/tj-django/django-migration-fixer
django django-makemigrations django-migration-fixer django-migrations django-models django-project github-actions makemigrations migrate migration migration-tool migrations resolves-migration-conflicts
Last synced: 3 months ago
JSON representation
Resolve multiple leaf nodes error running django migrations.
- Host: GitHub
- URL: https://github.com/tj-django/django-migration-fixer
- Owner: tj-django
- License: mit
- Created: 2021-05-21T19:53:50.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2025-03-26T06:05:15.000Z (4 months ago)
- Last Synced: 2025-03-30T11:02:06.349Z (3 months ago)
- Topics: django, django-makemigrations, django-migration-fixer, django-migrations, django-models, django-project, github-actions, makemigrations, migrate, migration, migration-tool, migrations, resolves-migration-conflicts
- Language: Python
- Homepage: https://tj-django.github.io/django-migration-fixer/
- Size: 2.06 MB
- Stars: 32
- Watchers: 2
- Forks: 5
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README

[](https://www.codacy.com/gh/tj-django/django-migration-fixer/dashboard?utm_source=github.com\&utm_medium=referral\&utm_content=tj-django/django-migration-fixer\&utm_campaign=Badge_Coverage)
[](https://codecov.io/gh/tj-django/django-migration-fixer)
[](https://www.codacy.com/gh/tj-django/django-migration-fixer/dashboard?utm_source=github.com\&utm_medium=referral\&utm_content=tj-django/django-migration-fixer\&utm_campaign=Badge_Grade)
[](https://github.com/tj-django/django-migration-fixer/actions/workflows/test.yml)
[](https://github.com/tj-django/django-migration-fixer/actions/workflows/deploy.yml)[](https://pypi.python.org/pypi/django-migration-fixer)
[](https://pypi.python.org/pypi/django-migration-fixer) [](https://pypi.python.org/pypi/django-migration-fixer) [](https://pepy.tech/project/django-migration-fixer)
[](https://github.com/search?o=desc\&q=tj-django+django-migration-fixer+language%3AYAML\&s=\&type=Code)
[](https://github.com/psf/black)# django-migration-fixer
Resolve django makemigrations `multiple leaf nodes in the migration graph` by ensuring that migration files and dependencies are always ordered regardless of remote changes, without having to run `python manage.py makemigrations --merge`.
## Table of Contents
* [Features](#features)
* [Installation](#installation)
* [Add `migration_fixer` to your INSTALLED\_APPS](#add-migration_fixer-to-your-installed_apps)
* [Usage](#usage)
* [Example](#example)
* [After merging the default branch](#after-merging-the-default-branch)
* [After running django-migration-fixer](#after-running-django-migration-fixer)
* [Assumptions](#assumptions)
* [Specifying a different default branch](#specifying-a-different-default-branch)
* [Setup using Github Actions](#setup-using-github-actions)
* [Inputs](#inputs)
* [Test Platforms](#test-platforms)
* [Found a Bug?](#found-a-bug)## Features
* Resolve migration conflicts on Pull Request branches
* Resolve migration conflicts on the default branch **(NOT RECOMMENDED)**## Installation
```bash
$ pip install django-migration-fixer
```### Add `migration_fixer` to your INSTALLED\_APPS
```python
INSTALLED_APPS = [
...,
"migration_fixer",
...,
]
```## Usage
Merge the changes from the default branch or the target branch of the pull request.
```bash
$ git checkout main # OR: develop/another parent feature branch
$ git pull
$ git checkout feature/xxxx
$ git merge main
```Fix the migration conflicts
```bash
$ python manage.py makemigrations --fix
```By default this uses `main` as the default branch
## Example
### After merging the default branch

### After running django-migration-fixer

## Assumptions
The final migration on the default branch would be used as the base for all subsequent migrations.
### Specifying a different default branch
Run:
```bash
$ python manage.py makemigrations -b master --fix
```## Setup using Github Actions
> NOTE: :warning:
>
> * To get this action to work you'll need to install [django-migration-fixer](#installation) and update your `INSTALLED_APPS` setting.### Inputs
| Input | type | required | default | description |
|:-------------:|:-----------:|:--------------:|:-----------------------------:|:--------------------------:|
| managepy-path | `string` | `true` | `./manage.py` | The location of manage.py. |
| default-branch | `string` | `false` | `${{ github.base_ref }}` | The default branch or
target branch of a Pull request. |
| force-update | `string` | `false` | | Force update the target branch
locally when git fetch fails. |
| skip-default-branch-update | `string` | `false` | | Skip pulling the latest
changes from the default branch. |```yaml
name: Fix django migrationson:
pull_request:
branches:
- mainjobs:
fix-migrations:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.6.x'- name: Upgrade pip
run: |
pip install -U pip- name: Install project dependencies
run: |
make install- name: Run django-migration-fixer
uses: tj-django/[email protected]
with:
managepy-path: /path/to/manage.py- name: Verify Changed files
uses: tj-actions/[email protected]
id: verify-changed-files
with:
files: |
/path/to/migrations- name: Commit migration changes
if: steps.verify-changed-files.outputs.files_changed == 'true'
run: |
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
git add /path/to/migrations
git commit -m "Updated migrations"- name: Push migration changes
if: steps.verify-changed-files.outputs.files_changed == 'true'
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: ${{ github.ref }}
```See: [here](https://github.com/tj-django/django-clone/blob/main/.github/workflows/migration-fixer.yml) for a working example.
## Test Platforms
* [`ubuntu-*`](https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#jobsjob_idruns-on)
* [`macos-*`](https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#jobsjob_idruns-on)
* [`windows-*`](https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#jobsjob_idruns-on)## Found a Bug?
To file a bug or submit a patch, please head over to [django-migration-fixer on github](https://github.com/tj-django/django-migration-fixer/issues).
If you feel generous and want to show some extra appreciation:
Support me with a :star:
[![Buy me a coffee][buymeacoffee-shield]][buymeacoffee]
[buymeacoffee]: https://www.buymeacoffee.com/jackton1
[buymeacoffee-shield]: https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png