简体   繁体   中英

Entity Framework 6.1.1 disable model compatibility checking

I am running into the following error after updating EF to version 6.1.1:

An unhandled exception of type 'System.InvalidOperationException' occurred in EntityFramework.dll

Additional information: The model backing the TvstContext context has changed since the database was created. Consider using Code First Migrations to update the database ( http://go.microsoft.com/fwlink/?LinkId=238269 ).

We could fix this in the past as described in this question: Where is modelBuilder.IncludeMetadataInDatabase in EF CTP5?

However, I can't seem to get rid of the error.

这应该工作,把它放在派生的DbContext的构造函数中:

Database.SetInitializer<MyContext>(null);

You can also set it in Web.config file

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <appSettings>    
    <add key="DatabaseInitializerForType YourNamespace.YourDbContext, AssemblyName"
            value="Disabled" />
    </appSettings>
</configuration>

Decision from: http://www.entityframeworktutorial.net/code-first/turn-off-database-initialization-in-code-first.aspx

To expand on Dabblernl's answers:

public ApplicationDbContext()
        : base("DefaultConnection", throwIfV1Schema: false)
    {
        Database.SetInitializer<ApplicationDbContext>(null);
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM