python - Django:合并迁移冲突的最佳方式

标签 python django django-migrations

我目前正在开发一个 dev 分支,有一天我需要将它合并到 master 分支。我的 dev 分支上有多达 20 个迁移文件,目前在 master 分支上有大约相同的数量。我需要在两个分支上进行迁移,这将导致迁移具有相同的前缀,

(例如 0003_auto)

换句话说,如果您有由 makemigrations 生成的具有相同前缀的迁移文件,那么处理此问题的最佳/安全方法是什么。

以下是我自己的两种看法(可能完全错误):

  1. 删除所有迁移文件,合并代码,然后运行新的 makemigrationsmigrate,这将只生成一个迁移文件。

  2. 使用 --merge 标志让 django 进行合并:

    makemigrations --merge
    

现在,了解所有这些后,我想知道处理此问题的最佳方法是什么。一般来说,我应该使用什么来正确合并冲突,并在每次模型更新时为我的项目提供一个新版本。

编辑

我认为提供一个循序渐进的解决方案对我和 future 的用户来说是理想的,因为有大量关于这个主题的信息,但似乎没有一个是简洁明了的。

最佳答案

来自Django docs :

Because migrations are stored in version control, you’ll occasionally come across situations where you and another developer have both committed a migration to the same app at the same time, resulting in two migrations with the same number.

Don’t worry - the numbers are just there for developers’ reference, Django just cares that each migration has a different name [emphasis added].

关于python - Django:合并迁移冲突的最佳方式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47097293/

相关文章:

python - 如何使用 django 1.7.3/postgres 迁移在数据库中设置默认列值?

mysql - Django alterField 在修改 max_length 时不保留 NOT NULL

python - 如何在 Seaborn 中创建区域图?

python - findAll中的匿名函数有什么用?

python - 使用Python解码未知编码的繁体中文字符串

python - 使用 Django 生成 LaTeX PDF 时出现 FileNotFoundError

python - Django级联删除反向外键

python - Django模型功能表现

python - django-import-export 如何处理 GenericRelations?

python - Django 迁移真的很糟糕