C# 在Identity Framework中添加新属性
首先,IdentityModels.cs如下所示: 使用Microsoft.AspNet.Identity.EntityFrameworkC# 在Identity Framework中添加新属性,c#,entity-framework,asp.net-identity,asp.net-identity-2,C#,Entity Framework,Asp.net Identity,Asp.net Identity 2,首先,IdentityModels.cs如下所示: 使用Microsoft.AspNet.Identity.EntityFramework namespace WebApplication2.Models { public class ApplicationUser : IdentityUser { } public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
namespace WebApplication2.Models
{
public class ApplicationUser : IdentityUser
{
}
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
public ApplicationDbContext()
: base("DefaultConnection")
{
}
}
}
当我单击“注册”时,它在此行失败:
var result = await UserManager.CreateAsync(user, model.Password);
这样说:
System.Data.SqlClient.SqlException:列名“Email”无效。
为什么我会犯这个错误?我错过了什么?谢谢
打开nuget控制台并键入:
update-database -force
在此之前,请确保已启用自动迁移。
您可以通过执行以下操作来打开它
enable-migrations
更改后是否更新了数据库架构?模型中的更改似乎没有反映在数据库中。@Pytalye我使用的是:
database.SetInitializer(new-DropCreateDatabaseAlways())代码>所以,在我添加电子邮件后,应该删除并创建数据库。我正在删除并在代码中重新创建数据库,它不应该工作吗?该命令工作了!但我想知道为什么。。为什么我需要它?谢谢,因为您似乎并不是通过删除db来更新模式。您可以通过帮助器类来完成。以下是一些人在其他地方提出的问题:
update-database -force
enable-migrations