Last post Oct 09, 2012 04:26 PM by Tim Coulter
Oct 09, 2012 03:42 PM|Tim Coulter|LINK
I have a VS2012 MVC3 project that uses Entity Framework 5.0 Code First and deploys to staging and production servers using Web Deploy. It uses code first data migrations to synchronize the databases with the model.
Until recently, everything was working correctly and changes to the model were correctly reflected in the database schemas.
However, after making some extensive code modifications, updates to the model classes are no longer being propagated to the staging server, with the result that it throws the following exception:
The model backing the 'xxxxx' context has changed since the database was created. Consider using Code First Migrations to update the database
Obviously, I haven't tried this against the production server, but I assume the result will be the same. However, everything still works fine locally, when invoked using update-database in Package Manager Console, so I assume the problem is
occurring somewhere in the Web Deploy pipeline.
In order to debug this, I am looking for some suggestions about where to look for clues. For example, is there something I can do during or after the VS2012 Publish process, to determine whether it actually sent the schema updates to IIS? And is there anything
I can do on the server to determine whether the server itself has a problem processing the updates sent to it?
Thanks, in advance, for your ideas.
Oct 09, 2012 03:55 PM|tdykstra|LINK
All Web Deploy does when you use migrations for deployment is configure some settings in the destination Web.config file. You can check to verify that those settings are getting configured correctly. Maybe you created a web.config transform that overrode
the changes? Basically, the Web.config file needs to specify the migrate-to-latest initializer. You can see examples of what the destination Web.config should look like here:
Oct 09, 2012 04:26 PM|Tim Coulter|LINK
Thanks for your very quick reply. This is really helpful and I am quite sure it is related to the problem I am seeing, as the code changes that I made before the problem occurred were an attempt to share the MVC project's Web.config with other projects in
the same solution (a couple of Windows services).
The problem I faced whilst implementing this was that I wanted these other projects to receive the transformed version of the Web.config, but since transformation doesn't naturally take place until publishing, I needed to find a way of forcing the transformation
duing the build. So I added the following to the configuration of the MVC project:
This seemed to work OK, but I wonder if this is what is likely to be causing my publish process to no longer work as before?
In any case, I'll investigate what you suggested and post the results here.
UPDATE: Yes, you were indeed right that my problem was caused by the way my own code was manipulating the Web.config (although it was a bit more complex that I guess above). In any case, knowing how Webdeploy delivers its schema-change payload will make
debugging any future issues a whole lot easier. Thanks again.