SqlException:无效的列名“NormalizedName”。列名“ConcurrencyStamp”无效。列名“NormalizedName”无效

Man*_*nny 4 asp.net asp.net-identity asp.net-core

为什么在 .NET Core Identity 上使用 PasswordSignInAsync 时出现异常? Microsoft.AspNetCore.Identity

await _signInManager.PasswordSignInAsync(user.UserName, Input.Password, Input.RememberMe, lockoutOnFailure: false);

An unhandled exception occurred while processing the request.
SqlException: Invalid column name 'NormalizedName'.
Invalid column name 'ConcurrencyStamp'.
Invalid column name 'NormalizedName'.
Microsoft.Data.SqlClient.SqlCommand+<>c.<ExecuteDbDataReaderAsync>b__164_0(Task<SqlDataReader> result)
Run Code Online (Sandbox Code Playgroud)

我可以创建用户,重置密码等等。'NormalizedName甚至不是 的一部分 Microsoft.AspNetCore.Identity。所有列都存在于我的表中

select LockoutEnd, TwoFactorEnabled, PhoneNumberConfirmed, PhoneNumber, ConcurrencyStamp, SecurityStamp, 
PasswordHash, EmailConfirmed, NormalizedEmail, Email, NormalizedUserName, UserName, Id, LockoutEnabled, AccessFailedCount
from [dbo].[AspNetUsers]
Run Code Online (Sandbox Code Playgroud)

Kon*_*nev 6

异常实际上来自表AspNetRoles而不是表AspNetUsers。如果您已将旧的 Asp.Net 迁移Identity到 Asp.Net Core,则需要将两个新字段添加到 Roles 表中。这是一个迁移:

public partial class Identity : Migration
{
    protected override void Up(MigrationBuilder migrationBuilder)
    {
        migrationBuilder.AddColumn<string>(
            name: "NormalizedName",
            table: "AspNetRoles",
            type: "nvarchar(256)",
            maxLength: 256,
            nullable: true);

        migrationBuilder.AddColumn<string>(
            name: "ConcurrencyStamp",
            table: "AspNetRoles",
            type: "nvarchar(max)",
            nullable: true);
    }

    protected override void Down(MigrationBuilder migrationBuilder)
    {
        migrationBuilder.DropColumn(
            name: "ConcurrencyStamp",
            table: "AspNetRoles");

        migrationBuilder.DropColumn(
            name: "NormalizedName",
            table: "AspNetRoles");
    }
}
Run Code Online (Sandbox Code Playgroud)

如果你想要完整的Identity迁移,包括用户、声明和其他表,你可以参考我对这个问题的回答: https: //stackoverflow.com/a/65003440/1348324