跳转到主要内容

解决迁移错误

项目描述

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

通过确保迁移文件和依赖关系始终按顺序排列(无论远程更改如何),解决由django makemigrations产生的迁移图中的多个叶子节点问题,无需运行python manage.py makemigrations --merge

目录

特性

  • 解决拉取请求分支上的迁移冲突
  • 在默认分支上解决迁移冲突(不建议使用)

安装

$ pip install django-migration-fixer

migration_fixer添加到您的INSTALLED_APPS

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

用法

合并默认分支或拉取请求的目标分支上的更改。

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

修复迁移冲突

$ python manage.py makemigrations --fix

默认情况下,使用 main 作为默认分支

示例

合并默认分支后

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

运行django-migration-fixer后

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

假设

默认分支上的最终迁移将用作所有后续迁移的基础。

指定不同的默认分支

运行

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

使用Github Actions设置

注意::warning

  • 要使此操作正常工作,您需要安装 django-migration-fixer 并更新您的 INSTALLED_APPS 设置。

输入

输入 类型 必需 默认值 描述
managepy-path 字符串 true ./manage.py manage.py 的位置。
default-branch 字符串 false ${{ github.base_ref }} 默认分支或
拉取请求的目标分支。
force-update 字符串 false 强制更新目标分支
在本地 git fetch 失败时。
skip-default-branch-update 字符串 false 跳过从默认分支
拉取最新更改。
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 }}

有关工作示例,请参阅:https://github.com/tj-django/django-clone

测试平台

发现了一个错误?

要提交错误报告或提交补丁,请访问 django-migration-fixer on github

如果您愿意并想表达额外的感谢

通过 :star 支持我

Buy me a coffee

项目详情


下载文件

下载您平台上的文件。如果您不确定选择哪个,请了解更多关于 安装软件包 的信息。

源分布

django-migration-fixer-1.3.6.tar.gz (10.8 kB 查看哈希值)

上传时间:

构建分布

django_migration_fixer-1.3.6-py2.py3-none-any.whl (14.9 kB 查看哈希值)

上传时间: Python 2 Python 3

由以下机构支持

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误记录 StatusPage StatusPage 状态页面