带有新数据库的EF6生成'支持< Database>自创建数据库以来,上下文已经发生变化。 [英] EF6 with new database generates 'The model backing the <Database> context has changed since the database was created.'

查看:442
本文介绍了带有新数据库的EF6生成'支持< Database>自创建数据库以来,上下文已经发生变化。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经通过迁移几周的时间开发了Code First数据库。我昨天添加了几张表,得到错误

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.

我正在运行VS2013。我有两个项目,一个是实体,另一个是MVC项目。我已经阅读了关于将实体移动到主要项目中的内容,但如果我听到过这样的话,听起来像是向后的解决方案。

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.

这个运行再次?

推荐答案

一个工作是将数据库初始化程序设置为null

A work around is to set the database initializer to null

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

这篇关于带有新数据库的EF6生成'支持&lt; Database&gt;自创建数据库以来,上下文已经发生变化。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆