我们何时应该使用合并迁移--meerge/mergeMigrations,以及何时使用SquashMigration我们可以通过管道执行这些命令,而不是团队中的每个开发人员手动执行这些命令吗?

推荐答案

让我们假设迁移文件fixture 有以下migrations.

./foo
    ./migrations
        0001_initial.py
        0002_userprofile.py
        0003_article.py
        0004_auto_add.py

以上是到现在为止的订单吗?因为我们是团队合作.

  • Developer1致力于article个功能,他已经创建了一个迁移0005_add_name_in_article.py
  • Developer2致力于userprofile个功能,他已经创建了0005_add_mobile_in_userprofile.py
  • Developer3致力于category个功能,他创建了0005_category.py个功能

Now that the situation has occurred when

  • Developer1会将代码合并到develop分支,迁移文件将是
./foo
    ./migrations
        0001_initial.py
        0002_userprofile.py
        0003_article.py
        0004_auto_add.py
        0005_add_name_in_article.py
  • Developer2会将代码合并到develop分支,迁移文件将是
./foo
    ./migrations
        0001_initial.py
        0002_userprofile.py
        0003_article.py
        0004_auto_add.py
        0005_add_name_in_article.py
        0005_add_mobile_in_userprofile.py

Here, the last two migrations have the same dependence, and this is breaking the order of the migration, while Developer2 migrating the migration after merging the develop branch django will provide the hit to merge the migration. After running the command, Django will create a new migration, 0006_merge_add_name_in_article_add_mobile_in_userprofile.py, which is merge the 0005_add_name_in_article.py and 0005_add_mobile_in_userprofile.py
The file contains the

  dependencies = [
        ('app_name', '0005_add_name_in_article'),
        ('app_name', '0005_add_mobile_in_userprofile'),
    ]

现在,Developer2个本地分支机构有以下migrations.

./foo
    ./migrations
        0001_initial.py
        0002_userprofile.py
        0003_article.py
        0004_auto_add.py
        0005_add_name_in_article.py
        0005_add_mobile_in_userprofile.py
        0006_merge_add_name_in_article_add_mobile_in_userprofile.py

现在Developer2家公司将筹集一个公关并合并,这样另一个发展音符就会与之冲突.

  • 同样的过程将为避免迁移冲突做Developer3.

什么是"合并迁移"?

合并迁移的主要目的是减少数据库级别上的冲突,同时以协作方式工作.并且它将生成用于管理迁移顺序的新迁移文件.

什么是"壁球迁徙"?

愿你心中浮现一个问题:how many unnecessary files will be created for migration?"

  • merge个迁移文件中,没有任何操作.
  • 可能有这样的表,在该表中,您添加了一列,然后将其移除,然后将其重新添加到可能创建的不同迁移的表中 压缩迁移的主要目的是优化迁移文件.但在挤压迁移之前,请参考docs,因为在某些情况下,它可能会很麻烦或引发迁移冲突.

我们可以通过管道执行这些命令,而不是团队中的每个开发人员手动执行吗?

不,根据上面合并和挤压迁移的用例,我们不能在管道上做,因为它的开发者有责任保持有序的迁移,根据Django社区,所有的迁移应该在团队中同步,所以我们不能在管道中做.

Python相关问答推荐

为什么带有dropna=False的groupby会阻止后续的MultiIndex.dropna()工作?

管道冻结和管道卸载

在线条上绘制表面

如何在python polars中停止otherate(),当使用when()表达式时?

"使用odbc_connect(raw)连接字符串登录失败;可用于pyodbc"

如何使用它?

在np数组上实现无重叠的二维滑动窗口

为什么Django管理页面和我的页面的其他CSS文件和图片都找不到?'

Tkinter菜单自发添加额外项目

在单次扫描中创建列表

python panda ExcelWriter切换动态公式到数组公式

ruamel.yaml dump:如何阻止map标量值被移动到一个新的缩进行?

python sklearn ValueError:使用序列设置数组元素

如何在Gekko中处理跨矢量优化

如果不使用. to_list()[0],我如何从一个pandas DataFrame中获取一个值?

在pandas中,如何在由两列加上一个值列组成的枢轴期间或之后可靠地设置多级列的索引顺序,

文本溢出了Kivy的视区

基于2级列表的Pandas 切片3级多索引

给定y的误差时,线性回归系数的计算误差

安装PyTorch时出现CondaVerificationError