该模型支持了“--context'环境已经改变,因为数据库创建 - 但是db是新的生产数据库 [英] The model backing the '--Context' context has changed since the database was created - but db is new production database

查看:235
本文介绍了该模型支持了“--context'环境已经改变,因为数据库创建 - 但是db是新的生产数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个错误的762时间,但这次我只要我试图访问我的生产现场,删除在Azure上的生产数据库,然后再发布我的网站后直接得到它。

I've got this error for the 762nd time but this time I am getting it as soon as I attempt to access my Production site, straight after deleting the 'production' database on Azure and then publishing my site.

The model backing the 'PropertyContext' context has changed since the database was created. Consider using Code First Migrations to update the database

我删除了数据库,因为我不能修复这个问题的任何其他方式,但它仍然无法正常工作。

I deleted the database because I couldn't fix this issue any other way but it still doesn't work.

一些重要的点:


  • 我使用EF6和出版天青。

  • 这是1 2的项目/使用相同的回购项目用地。我也没结果
    问题的另外一个,仅这一个。

  • 我已经试过第一次发布问题项目(删除DB后),
    第二与相同的结果。

  • 我试图删除这两个网站和Azure的数据库,并再次启动

  • 我曾尝试删除所有的迁移,并用新的数据模型开始

  • 我已经试过在我的Global.asax以下(在这两个项目)

  • I'm using EF6 and publishing to Azure.
  • This is 1 of 2 projects/sites that uses the same Repo project. I have no
    problems with the other one, just this one.
  • I have tried publishing the problem project first (after deleting the db) and second with the same result.
  • I have tried deleting both WEBSITES and the DB from Azure and starting again
  • I have tried deleting all migrations and starting with a fresh data model
  • I have tried the following in my Global.asax (in both projects)

Database.SetInitializer PropertyContext>(NULL); < - 所以不会让我把第一<

Database.SetInitializer PropertyContext>(null); <-- SO won't let me put the first <

Database.SetInitializer(new MigrateDatabaseToLatestVersion<PropertyContext, MyConfiguration>());
new PropertyContext().Database.Initialize(true);

我使用.NET 4.5

I'm using .net 4.5

为什么我会得到一个新的数据库上的这个错误,我怎么能得到这个网站的工作?

Why am I getting this error on a new database and how can I get this site to work?

推荐答案

刚跑进ASP.Net应用程序相同的错误。在我来说,我没有使用code第一,但我用这显然使用code首先标准ASP.Net认证供应商,和认证是因为这个问题打破了。

Just ran into the same error in ASP.Net application. In my case I did not use Code First, but I used standard ASP.Net authentication provider which apparently uses Code First, and authentication was broken because of this issue.

有关我的解决方法是删除 DBO .__ MigrationHistory 表,认证开始工作之后的罚款。 注意!这个解决方案并不适合每一个人!这将解决这个问题,但其潜在的风险。

For me the solution was to drop the dbo.__MigrationHistory table, authentication started working fine after that. Be aware! This solution is not for everyone! This will fix the problem, but it is potentially risky.

ASP.Net身份验证提供者在数据库中自动创建表:

ASP.Net authentication provider automatically creates tables in your database:


  • AspNetRoles

  • AspNetUsers

  • AspNetUserRoles

  • AspNetUserClaims

  • AspNetUserLogings

该表是默认为空,如果您还没有创建任何新的登录你的网站,你可以使用上面的快速和肮脏的解决方案。如果你真的关心preserving用户信息或只是珍玩code首先迁移是如何工作的,请按照下列步骤操作:

The tables are empty by default, if you haven't created any new logins for your web site, you can use "quick and dirty" solution above. If you do care about preserving user information or just curios how Code First migrations work, follow these steps:


  • 打开你的web.config文件,并检查你有你的数据库的连接字符串的名称。这将是下一条记录&LT;是connectionStrings方式&gt; 元素

  • 打开包管理器控制台:

  • Open your Web.config file and check the name of the connection string you have for your database. It will be one of the records under <connectionStrings> element.
  • Open Package Manager Console:

工具 - >库包管理器 - >程序包管理器控制台

    Update-Database -ConnectionStringName MyConnectionStringName

与您web.config中抬头的实际名称替换MyConnectionStringName。

Replace the MyConnectionStringName with the actual name you looked up in web.config.

此命令的结果,你会看到一个新的文件夹迁移由更新,数据库命令生成一串code的。重新构建并重新部署应用程序,你的新的迁移code将在启动时执行,将使数据库模式同步与ASP.Net身份验证提供code的更新版本。

As a result of this command you will see a new folder "Migrations" with a bunch of code generated by the Update-Database command. Re-build and re-deploy your app, your new migration code will be executed on startup and would bring the database schema in sync with an updated version of ASP.Net authentication provider code.

这篇关于该模型支持了“--context'环境已经改变,因为数据库创建 - 但是db是新的生产数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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