如何在 ASP.NET Core 3.1 中的 AspnetUser 中添加列?

Rup*_*pak 0 c# asp.net-mvc asp.net-identity asp.net-core asp.net-core-3.1

我创建了一个具有以下属性的应用程序用户类:

 public class ApplicationUser:IdentityUser
 {
    public string RandomPassword { get; set; }
 }
Run Code Online (Sandbox Code Playgroud)

我已将启动更新为:

services.AddIdentity<ApplicationUser, IdentityRole>(options => options.SignIn.RequireConfirmedAccount = true)
            .AddEntityFrameworkStores<ApplicationDbContext>().AddDefaultTokenProviders();
Run Code Online (Sandbox Code Playgroud)

但我的迁移为空。我希望 RandomPassword 作为 AspNetUser 表的列。

Mar*_*cel 5

您可能在 DbContext 中缺少这个定义

public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
   // omitted 
}

Run Code Online (Sandbox Code Playgroud)