Skip to main content

logo

Codacy Badge codecov Total alerts Language grade: Python Codacy Badge

Test Upload Python Package Run linters Updates Code style: black

PyPI PyPI - Python Version PyPI - Django Version Downloads Public workflows that use this action.

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

  • Resolve migration conflicts on Pull Request branches
  • Resolve migration conflicts on the default branch (NOT RECOMMENDED)

Installation

$ pip install django-migration-fixer

Add migration_fixer to your INSTALLED_APPS

INSTALLED_APPS = [
    ...,
    "migration_fixer",
    ...,
]

Usage

Merge the changes from the default branch or the target branch of the pull request.

$ git checkout main # OR: develop/another parent feature branch
$ git pull
$ git checkout feature/xxxx
$ git merge main

Fix the migration conflicts

$ python manage.py makemigrations --fix

By default this uses main as the default branch

Example

After merging the default branch

Screen Shot 2021-07-06 at 2 21 46 PM

After running django-migration-fixer

Screen Shot 2021-07-06 at 2 22 31 PM

Assumptions

The final migration on the default branch would be used as the base for all subsequent migrations.

Specifying a different default branch

Run:

$ python manage.py makemigrations -b master --fix

Setup using Github Actions

NOTE: ⚠️

  • To get this action to work you'll need to install django-migration-fixer 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.
name: Fix django migrations

on:
  pull_request:
    branches:
      - main

jobs:
  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/django-migration-fixer@v1.3.6
        with:
          managepy-path: /path/to/manage.py

      - name: Verify Changed files
        uses: tj-actions/verify-changed-files@v7.1
        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: https://github.com/tj-django/django-clone for a working example.

Test Platforms

Found a Bug?

To file a bug or submit a patch, please head over to django-migration-fixer on github.

If you feel generous and want to show some extra appreciation:

Support me with a ⭐

Buy me a coffee

Metadata

Release files for django-migration-fixer 1.3.6

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-migration-fixer 1.3.6
File Size Uploaded Provenance
django-migration-fixer-1.3.6.tar.gz 10.8 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for django-migration-fixer 1.3.6
File Interpreter ABI Platform
django_migration_fixer-1.3.6-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 25.7 kB

Release files / django-migration-fixer-1.3.6.tar.gz

Download URL django-migration-fixer-1.3.6.tar.gz
Size 10.8 kB
Tags Source
SHA-256 checksum
How to use checksums
930e6529a4955a3c5f0d918d5bd3c0f545a2bee9607d96cd51462bd5f9e11c1e
BLAKE2b-256 checksum
How to use checksums
6ad0404df3679fcd43738dfa031798fa6b2d18fa4d734b27f04a2534e0e5b0b3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.8.3 pkginfo/1.8.3 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.64.1 CPython/3.6.15

Release files / django_migration_fixer-1.3.6-py2.py3-none-any.whl

Download URL django_migration_fixer-1.3.6-py2.py3-none-any.whl
Size 14.9 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
ca4641bf5ff42156a81cf095f5534930b442c600e065f8009dab5951d02dba71
BLAKE2b-256 checksum
How to use checksums
df65176211805d1916bc2ed8fb7ed0f8937e874fbe2d5d9aff2adc16f2ea1dcd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.8.3 pkginfo/1.8.3 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.64.1 CPython/3.6.15

Security for django-migration-fixer 1.3.6

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.

Release history Release notifications | RSS feed

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