I am using EntityFramework 6.0.2 with explicit (not automatic) code-first migrations. My model is well established - I've been using this app for months and there have been many migrations added. The app uses MVC5.
After upgrading to MVC5.1, I'm now in a situation where the EF migration tools within VS see the model differently to the runtime. Running Add-Migration
creates an empty migration, and Update-Migration
thinks all outstanding migrations have been applied. However, when trying to start the site, it fails with AutomaticMigrationsDisabledException
:
Unable to update database to match the current model because there are
pending changes and automatic migration is disabled. Either write the
pending model changes to a code-based migration or enable automatic
migration. Set DbMigrationsConfiguration.AutomaticMigrationsEnabled to
true to enable automatic migration.
This appears to be related to elements in my model classes which have both [Required]
and [AllowHtml]
set on them. These are not new properties, but the first explicit migration I created after updating to MVC5.1 caused any properties with both of these attributes to be recreated without NOT NULL. This is when I began noticing the problem, as it's the point at which I could no longer run my app.
I do not want to remove the [AllowHtml]
attribute. I'd like to find out why the Visual Studio tooling is seeing the model differently to the runtime. I have created a simple test project using MVC5.0, upgraded it to 5.1, and it did NOT show the same behaviour, so I'm looking for pointers on what to look for in my main project which could be affecting this.
There is another question with a similar problem, but not related to MVC5.1, suggesting this is probably to do with version differences somewhere. All of the many assemblies within my application are referencing the same version of all external dependencies such as MVC and EF.
I've reverted my code to MVC5.0 which made the problem go away for now, but the problem is still neither understood nor fixed (I still need to update to 5.1 at some point!).