Search code examples
entity-frameworkalter

EF: Getting "The model backing ...has changed" error, though I've altered well the schema


I am not worried about rollbacks (ie: Down() method), and would like to work always on the latest code modification, so I'm not using Code Migrations.

I changed this:

 int SomeProperty {get; set;}

To this:

 int? SomeProperty {get; set;}

And then I modified the database schema (altering the column SomeProperty to allow NULLS).

Although this last part, I'm still getting the error:

The model backing the <Database> context has changed ...

What other change do I need to do so that the schema matches the model if that (int to int?) is the only change I've done?


Solution

  • The real answer to this is a bug in EF.
    In Global.asax.cs this line is needed:

    public class MvcApplication : System.Web.HttpApplication
    {
        protected void Application_Start()
        {
            //...
    
            // Weird fix before using any DbContext instance <--- THIS
            Database.SetInitializer<MyDbContext>(null);
        }