Entity Framework pitfalls - Generic-Voting-Application/voting-application GitHub Wiki

With multiple developers working with EF, there can be non-obvious conflicts. The most common of these is that two developers working on separate branches both add an explicit migration. Once these both merge, the latter migration "wins" in the sense that it's model of the code is the one that EF considers when determining if the database is up to date. This causes confusion, as it appears that EF wants to re-scaffold a change that's already applied to the db, and if allowed to do so, it will fail.

To prevent this, if you're scaffolding a migration, before creating a pull request make sure you're up to date with the target branch, and then re-scaffold your migration. If there are changes in the .resx, then this indicates that another migration has been run, and you'll need to replace your original scaffold with the new one to ensure that the model inserted into the database is correct.

It also helps to just let people know if you're scaffolding changes.

We currently also have issues with old auto-migrations. If you attempt to run the project and let it create the db from scratch, then it will fail, as the auto-migrations would cause data-loss (if there was any data there). To fix this, you can let it create the db then fail to run the migrations. Once it's created the db, run update-database --force to force the auto-migrations through.