解决迁移错误
项目描述
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
作为默认分支
示例
合并默认分支后
运行django-migration-fixer后
假设
默认分支上的最终迁移将用作所有后续迁移的基础。
指定不同的默认分支
运行
$ 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 支持我
项目详情
下载文件
下载您平台上的文件。如果您不确定选择哪个,请了解更多关于 安装软件包 的信息。
源分布
django-migration-fixer-1.3.6.tar.gz (10.8 kB 查看哈希值)
构建分布
关闭
哈希值 for django_migration_fixer-1.3.6-py2.py3-none-any.whl
算法 | 哈希摘要 | |
---|---|---|
SHA256 | ca4641bf5ff42156a81cf095f5534930b442c600e065f8009dab5951d02dba71 |
|
MD5 | c1c955e79c385cf3ab7661da6679b2a4 |
|
BLAKE2b-256 | df65176211805d1916bc2ed8fb7ed0f8937e874fbe2d5d9aff2adc16f2ea1dcd |