在小組環境中的移轉Migrations in Team Environments

當小組環境中使用移轉,注意額外模型快照集檔案。When working with Migrations in team environments, pay extra attention to the model snapshot file. 這個檔案會告訴您是否隊友的移轉會合併完全與您的是否您需要解決衝突,請重新建立您的移轉前共用文件。This file can tell you if your teammate's migration merges cleanly with yours of if you need to resolve a conflict by re-creating your migration before sharing it.

合併Merging

當您合併從您的小組成員的移轉時,您可能取得衝突您模型的快照集檔案中。When you merge migrations from your teammates, you may get conflicts in your model snapshot file. 如果這兩項變更是不相關,merge 是簡單式,可同時存在兩個移轉。If both changes are unrelated, the merge is trivial and the two migrations can coexist. 例如,可能看起來像這樣的 customer 實體類型設定中會出現合併衝突:For example, you may get a merge conflict in the customer entity type configuration that looks like this:

<<<<<<< Mine
b.Property<bool>("Deactivated");
=======
b.Property<int>("LoyaltyPoints");
>>>>>>> Theirs

因為這兩個屬性需要最終模型中存在,請加入這兩個屬性完成合併。Since both of these properties need to exist in the final model, complete the merge by adding both properties. 在許多情況下,版本控制系統可能會自動為您合併這類變更。In many cases, your version control system may automatically merge such changes for you.

b.Property<bool>("Deactivated");
b.Property<int>("LoyaltyPoints");

在這些情況下,您的移轉和移轉您的小組成員會彼此獨立。In these cases, your migration and your teammate's migration are independent of each other. 其中任一無法先套用,因為您不需要任何額外變更您的移轉之前與您的小組共用。Since either of them could be applied first, you don't need to make any additional changes to your migration before sharing it with your team.

解決衝突Resolving conflicts

有時您可能會遇到,則為 true 的衝突合併模型快照集時。Sometimes you encounter a true conflict when merging the model snapshot model. 例如,您和您的小組可能每個重新命名相同的屬性。For example, you and your teammate may each have renamed the same property.

<<<<<<< Mine
b.Property<string>("Username");
=======
b.Property<string>("Alias");
>>>>>>> Theirs

如果您遇到這類衝突,解決重新建立您的移轉。If you encounter this kind of conflict, resolve it by re-creating your migration. 請依照下列步驟:Follow these steps:

  1. 「 合併 」 和 「 復原您在合併之前的工作目錄為中止Abort the merge and rollback to your working directory before the merge
  2. 移除您的移轉 (但保留模型的變更)Remove your migration (but keep your model changes)
  3. 將您的小組成員變更合併至您的工作目錄Merge your teammate's changes into your working directory
  4. 重新加入您的移轉Re-add your migration

執行此動作後的兩個移轉作業都可以套用正確的順序。After doing this, the two migrations can be applied in the correct order. 其移轉會先套用,重新命名的資料行別名,之後您移轉重新命名它UsernameTheir migration is applied first, renaming the column to Alias, thereafter your migration renames it to Username.

小組的其餘部分,可以安全地共用您的移轉。Your migration can safely be shared with the rest of the team.