我正在使用
创建初始迁移Add-Migration InitialCreate
但是当我从IdentityDbContext更新我的数据库表时,我没有创建异常。
那么如何从IdentityDbContext为AspNetUser表创建迁移?
关心teamol
答案 0 :(得分:0)
您可以在IdentityModels.cs文件中的AspNetUser表中添加自定义字段。
首先在IdentityModels中将自定义值添加到ApplicationUser类:
namespace YourProjectName.Models
{
public class ApplicationUser : IdentityUser
{
public string Email { get; set; }
public string NameSurname { get; set; }
public string ProfilePhotoRoute { get; set; }
public string Title { get; set; }
}
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
public ApplicationDbContext()
: base("DefaultConnection")
{
}
}
之后,在包管理器控制台中输入“Add-Migration NewMigration”命令。
最后,在包管理器控制台中输入“Update-Database”命令。
如果您在web.config中声明的连接字符串为true,则可以使用这种方式成功更新数据库。