[英]How to add a column in an existing AspNetUsers table
I need to add several columns to the dbo.AspNetUsers. 我需要在dbo.AspNetUsers中添加几个列。 This has been created using the "Individual Accounts" option.
这是使用“个人帐户”选项创建的。 I have tried what I have searched on the internet but I can't get it to work.
我已经尝试过在互联网上搜索过的内容,但我无法让它工作。 Please see my code:
请看我的代码:
In the generated ApplicationDbContext I modified it to be like so: 在生成的ApplicationDbContext中,我修改它是这样的:
public class ApplicationDbContext : IdentityDbContext
{
[Required]
[MaxLength(50)]
public string FirstName { get; set; }
[MaxLength(50)]
public string MiddleName { get; set; }
[Required]
[MaxLength(50)]
public string LastName { get; set; }
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
: base(options)
{
}
}
Then I ran the add-migration but I just got an empty Migration file. 然后我运行了添加迁移,但我得到了一个空的迁移文件。
using Microsoft.EntityFrameworkCore.Migrations;
namespace BlazorApp4.Data.Migrations
{
public partial class ModifiedUserDatabase : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
}
protected override void Down(MigrationBuilder migrationBuilder)
{
}
}
}
But I still tried the update-database but nothing has been added to the table that I needed. 但我仍然尝试了更新数据库,但没有添加到我需要的表中。
I think I need to place it in the ApplicationUser that inherits IdentityUser. 我想我需要将它放在继承IdentityUser的ApplicationUser中。 But I don't see it anywhere in my blazor application.
但我在我的blazor应用程序中没有看到它。
Could you please help me with this? 你能帮帮我吗? Thank you.
谢谢。
Steps: 脚步:
IdentityUser
IdentityUser
find all other occurences of IdentityUser
in your .cs and .razor files and replace with ApplicationUser
. 在.cs和.razor文件中找到
IdentityUser
所有其他出现,并替换为ApplicationUser
。
inherit the context with the new class as Type argument: 使用新类作为Type参数继承上下文:
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
when you override OnModelCreating, don't forget to call 当你重写OnModelCreating时,不要忘记打电话
base.OnModelCreating(builder);
now you can add-migrate 现在你可以添加 - 迁移
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.