Reputation: 71
I upgraded a project with code first migrations from EF5 to EF6. I followed all the instructions in http://msdn.microsoft.com/en-us/library/upgradeef6.aspx . Everything compiles fine. But when I run a unit test when it comes to read from the database it throws an InvalidOperationException: The model backing the context has changed since the database was created. Obviously, the model has not changed but it seems to not like the EF5 migrations.
I tried to do an add-migrations to see what it might want to upgrade, but it fails saying the existing migrations have not been applied. Note, I had to uninstall and re-install EF6 due to it not installing correctly, could this have reset something?
I also note that the _MigrationHistory table in EF5 is a SystemTable but in EF6 it isn't. I know the table is different but I was expecting this to all be backward compatible?
Added: Can anyone tell me how add-migrations decides which migrations have not been performed when it doesn't connect to the database so has no access to _MigrationsHistory? If I can understand that maybe I can understand what has gone wrong.
Any ideas on what I've done wrong? Thanks.
Upvotes: 0
Views: 115
Reputation: 71
OK. For all those out there wondering what the answer is. There are two parts.
When you upgrade to EF6 you do have to migrate the database as it renames some tables, migrates the _MigrationHistory table and also creates plenty of new indexes. So the Upgrading To EF6 page is missing the information that you will need to migrate your database.
Lastly, and this was obvious really, you DO need a connection string with Add-Migration. Documentation I had was incorrect, the ConnectionStringName parameter was missing, hence it thought none of the migrations had been done as it was looking on the default IIS Express database, not the actual IIS database.
Upvotes: 1