6
votes

I frequently encounter the following situation with Entity Framework code first migrations. I add some migrations and update the database with them successfully. When later I wish to add a new migration, the Add-Migration command complains that its "Unable to generate an explicit migration because the following explicit migrations are pending...". I.e., it seems to forget that its already applied those migrations previously and therefore they shouldn't be now considered as pending. If I try to workaround this issue, Update-Database indicates "Unable to update database to match the current model because there are [new] pending changes...". I don't understand why EF migrations getting out of sync since I'm only making changes to the model.

4
Not sure how much it will help, but see this question/answer: stackoverflow.com/questions/16952413/… - Steve
Thanks Steve. It appears this issue is caused by a VS 2013 bug in that VS 2013 doesn't properly update a DLL-reference (as opposed to a project-ref) when the reference is deleted and then added again from the database-context project's bin folder (even if Clean Solution is called in between). The referring project's bin doesn't show the updated database-context DLL even after subsequent compilation. Hence, the DLL's model is out-of-date with the database which has already been updated by the data-context project. - CalvinDale
You should post that as an answer to your own question, so when others search for it they might find your explanation. - Steve

4 Answers

13
votes

For me the issue was that we had renamed the namespace of the migration 2014123456_Initial.cs.
But VS had not regenerated the namespace in its associated 2014123456_Initial.Designer.cs.

Once the Designer.cs was changed to use the same namespace, it all started working again.

0
votes

I was having the same issue and the solution was:

  1. Clean solution;
  2. Build the project which has migrations enabled (just to make sure);
  3. Build the Solution again;

This is pretty much equivalent of using the Rebuild Solution option in the Build menu.

0
votes

I had the exact same problem and could not resolve it.

To add to IamDOM solution ALSO add an empty migration and update database.

For example:

Add-Migration Test

Update-Database

It worked for me few times now.

0
votes

I found that VS had got confused somehow and not actually added the migrations to the .csproj. Closing, re-opening VS then re-including the migration in the project and saving-all worked.