我目前正在开发一个 dev 分支,有一天我需要将它合并到 master 分支。我的 dev 分支上有多达 20 个迁移文件,目前在 master 分支上有大约相同的数量。我需要在两个分支上进行迁移,这将导致迁移具有相同的前缀,
(例如 0003_auto
)
换句话说,如果您有由 makemigrations
生成的具有相同前缀的迁移文件,那么处理此问题的最佳/安全方法是什么。
以下是我自己的两种看法(可能完全错误):
删除所有迁移文件,合并代码,然后运行新的
makemigrations
和migrate
,这将只生成一个迁移文件。使用
--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/