例外ASP.NET身份之后升级到2.0 [英] exception after upgrade ASP.NET Identity to 2.0
问题描述
我的项目:VS2013,实体框架,Web表单,数据库首先,身份
my project: VS2013, Entity Framework, Web forms, database first, Identity
今日(2014年4月15日)我更新了我的项目的所有的NuGet包。其中,身份升级到2.0.0.0。
I updated all NuGet packages of my project today (2014-4-15). Among them, Identity is upgraded to 2.0.0.0.
我以为一切进展不错,但不幸的是,当我运行应用程序时,下面的语句给出了一个例外。
I thought things were going good, but unfortunately when I run the application, the following statement gives an exception.
namespace xxx.Models
{
// You can add User data for the user by adding more properties to your User class, please visit http://go.microsoft.com/fwlink/?LinkID=317594 to learn more.
public class ApplicationUser : IdentityUser
{
}
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
public ApplicationDbContext()
: base("MyConnection")
{
}
}
...
}
的异常信息如下。它要求我做code第一次迁徙。但我的项目是一个数据库首先web表单的项目。我怎样才能解决这个问题?谢谢!
The exception information is as follows. It asks me to do Code First Migration. But my project is a Database First webforms project. How can I solve this problem? Thanks!
'System.InvalidOperationException'类型的异常出现在Microsoft.AspNet.Identity.EntityFramework.dll但在用户code没有处理
An exception of type 'System.InvalidOperationException' occurred in Microsoft.AspNet.Identity.EntityFramework.dll but was not handled in user code
附加信息:该模型支持了ApplicationDbContext'环境已经改变,因为该数据库已创建。
这可能发生,因为ASP.NET框架标识采用的模式已经改变或模型的应用程序中使用发生了变化。
要解决此问题,您需要更新您的数据库。考虑使用code首先迁移到更新数据库(<一个href=\"http://go.microsoft.com/fwlink/?LinkId=301867\">http://go.microsoft.com/fwlink/?LinkId=301867).
在您使用code首先迁移更新数据库,请通过设置throwIfV1Schema =在ApplicationDbContext在你的应用程序的构造虚假禁用ASP.NET身份的架构一致性检查。
公共ApplicationDbContext():基地(ApplicationServices,throwIfV1Schema:FALSE)
Additional information: The model backing the 'ApplicationDbContext' context has changed since the database was created.
This could have happened because the model used by ASP.NET Identity Framework has changed or the model being used in your application has changed.
To resolve this issue, you need to update your database. Consider using Code First Migrations to update the database (http://go.microsoft.com/fwlink/?LinkId=301867).
Before you update your database using Code First Migrations, please disable the schema consistency check for ASP.NET Identity by setting throwIfV1Schema = false in the constructor of your ApplicationDbContext in your application.
public ApplicationDbContext() : base("ApplicationServices", throwIfV1Schema:false)
推荐答案
您需要通过执行错误说什么禁用架构的一致性。这是当你从1.0版本升级到2.0发生一次的事情。
You need to disable the schema consistency by doing what the error says. This is one time thing that happens when you upgrade from version 1.0 to 2.0.
public ApplicationDbContext() : base("MyConnection", throwIfV1Schema:false)
下一步 - 做迁移。
Next step - do the migrations.
一切都应该后工作,你可以删除这个 throwIfV1Schema:假
Everything should work after that and you can remove this throwIfV1Schema:false
您也可以看看<一个href=\"http://blogs.msdn.com/b/webdev/archive/2013/12/20/updating-asp-net-applications-from-asp-net-identity-1-0-to-2-0-0-alpha1.aspx\">this更多资讯
这篇关于例外ASP.NET身份之后升级到2.0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!