在小組環境中的移轉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 or 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. 如果這兩個變更無關,只是一般規則合併,並可同時存在兩個移轉。If both changes are unrelated, the merge is trivial and the two migrations can coexist. 例如,可能看起來像這樣的客戶實體型別組態中會出現合併衝突: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 的衝突合併 model 快照集時。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.