gpt4 book ai didi

在团队中工作时 Django South 迁移冲突

转载 作者:IT王子 更新时间:2023-10-29 00:46:21 25 4
gpt4 key购买 nike

我有一个关于在团队中工作时如何使用 Django-South 的简短问题。

如果两个人同时根据对同一文件的更改创建迁移文件会怎样?

例如,A 和 B 正在开发同一个 Django 应用程序。他们在不同的分支工作,都在迁移 005。现在,A 和 B 都修改了 apple/models.py 并使用 startmigration 创建了迁移文件。他们都在迁移 006 但迁移文件 006 完全不同。我猜当他们 merge 他们的分支时,South 可能有一些错误。

是否有解决此冲突的解决方法?还是 South 足够聪明,可以自行解决?

最佳答案

南方的documentation讨论这个问题:

The issue with teams and migrations occurs when more than one person makes a migration in the same timeslot, and they both get committed without the other having been applied. This is analogous to two people editing the same file in a VCS at the same time, and like a VCS, South has ways of resolving the problem.

If this happens, the first thing to note is that South will detect the problem, and issue a message like this:

Inconsistent migration history
The following options are available:
--merge: will just attempt the migration ignoring any potential dependency
conflicts.

If you re-run migrate with --merge, South will simply apply the migrations that were missing out-of-order. This usually works, as teams are working on separate models; if it doesn’t, you’ll need to look at the actual migration changes and resolve them manually, as it’s likely they’ll conflict.

The second thing to note is that, when you pull in someone else’s model changes complete with their own migration, you’ll need to make a new empty migration that has the changes from both branches of development frozen in (if you’ve used mercurial, this is equivalent to a merge commit). To do so, simply run:

./manage.py schemamigration --empty appname merge_models

(Note that merge_models is just a migration name; change it for whatever you like)

The important message here is that South is no substitute for team coordination - in fact, most of the features are there purely to warn you that you haven’t coordinated, and the simple merging on offer is only there for the easy cases. Make sure your team know who is working on what, so they don’t write migrations that affect the same parts of the DB at the same time.

关于在团队中工作时 Django South 迁移冲突,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11841657/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com