EF6 with new database generates 'The model backing the <Database> context has changed since the database was created.'

折月煮酒 提交于 2019-12-12 00:50:47

问题


I have been developing a Code First database via migrations for a couple of weeks. I added a few tables yesterday and got the error

The model backing the 'DanceDb' context has changed since the database was created.

After trying a couple of things I dropped the database, removed all code migrations, cleaned the solution, added a single migration and ran an Update-Database but I still get the same error.

If I run Add-Migrations again, nothing is generated so something thinks they're the same.

I'm running VS2013. I have two projects, one for the entities and the other for the MVC project. I've read about moving the entities into the main project but that sounds like a backwards solution if I've ever heard one.

What on earth do I do to get this running again?


回答1:


A work around is to set the database initializer to null

public class DanceDb : DbContext
{
    public DanceDb() : base("name=DanceEntities")
    {
        Database.SetInitializer<DanceDb>(null);
    }
}


来源:https://stackoverflow.com/questions/22314954/ef6-with-new-database-generates-the-model-backing-the-database-context-has-ch

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!