The starting information how the situation related to merging migrations can be read in this great post from Anders Abel.
I just have an extension to it for a specific situation.
Simple case merge migration
This is the case when the merged migration (from the source branch) is the last migration on the target branch. The code to that is fairly easy described in the above linked post. You only need to re-scaffold the code first model (in the designer file of the migration). Just a notice: don’t use the “force” option here, so you don’t add all the changes to your merged migration. Example below:
Complicated case merge migration
If your migration is not the last one in the target branch, you have to do a couple of other things.
- Clean solution
- Delete database (for simplicity, it would be enough to update/downgrade the database to the target merged migration)
- Exclude migrations after the merged migration from the project
- Re-scaffold the merged migration as described above
- Include one of the excluded migrations
- Re-scaffold it as described above
- Repeat step 5 and 6 till you included all migrations
This way was working for me, however it is not so intuitive. Please comment on my post if you find an easier way.