gpt4 book ai didi

entity-framework - 迁移到 Asp.Net Identity 2.0 : new columns not being created in AspNetUsers table

转载 作者:行者123 更新时间:2023-12-04 04:59:25 26 4
gpt4 key购买 nike

当我尝试使用 Identity 2.0 和默认的 MVC 5 应用程序注册新用户时,出现以下错误:

Invalid column name 'Email'.
Invalid column name 'EmailConfirmed'.
Invalid column name 'PhoneNumber'.
Invalid column name 'PhoneNumberConfirmed'.
Invalid column name 'TwoFactorEnabled'.
Invalid column name 'LockoutEndDateUtc'.
Invalid column name 'LockoutEnabled'.
Invalid column name 'AccessFailedCount'.
(repeats 2 more times, I have a total of 4 test users in AspNetUsers table.)

我有一个小应用程序,我刚刚从 MVC4/Identity 1.0 升级到 MVC5/Identity 2.0,所以我让 Identity 1.0 列(UserName、PasswordHash、SecurityStamp、Discriminator)工作。
  • 我正在使用带有标准 Identity 1.0 表的远程托管 SQL2012 数据库。
  • 我创建了一个“干净”的项目,注册了一个用户,它在 localDB 上运行良好。
  • 我在远程数据库上成功运行了“add-migration initial”和“update-database”。
  • 我最初关注 this official guide ,并且没有生成第 5 步中的代码。我尝试手动粘贴它并再次运行“update-database -verbose”。似乎成功完成,但仍然出现错误。

  • 感谢任何帮助!

    迁移和 configuration.cs 文件
    internal sealed class Configuration : DbMigrationsConfiguration<FactBanker.Models.ApplicationDbContext>
    {
    public Configuration()
    {
    AutomaticMigrationsEnabled = true;
    }

    protected override void Seed(FactBanker.Models.ApplicationDbContext context)
    {

    }
    }

    }

    我的 V023 migration.cs 文件
    Up() 和 Down() 方法都是空的。
    public partial class V023 : DbMigration
    {
    public override void Up()
    {

    }

    public override void Down()
    {

    }
    }

    最佳答案

    我遇到了同样的问题。我使用了这个手动迁移,但我还没有遇到任何其他问题。

    public override void Up()
    {
    RenameColumn(table: "dbo.AspNetUserClaims", name: "User_Id", newName: "UserId");
    RenameIndex(table: "dbo.AspNetUserClaims", name: "IX_User_Id", newName: "IX_UserId");
    DropPrimaryKey("dbo.AspNetUserLogins");
    AddColumn("dbo.AspNetUsers", "Email", c => c.String(maxLength: 256));
    AddColumn("dbo.AspNetUsers", "EmailConfirmed", c => c.Boolean(nullable: false));
    AddColumn("dbo.AspNetUsers", "PhoneNumber", c => c.String());
    AddColumn("dbo.AspNetUsers", "PhoneNumberConfirmed", c => c.Boolean(nullable: false));
    AddColumn("dbo.AspNetUsers", "TwoFactorEnabled", c => c.Boolean(nullable: false));
    AddColumn("dbo.AspNetUsers", "LockoutEndDateUtc", c => c.DateTime());
    AddColumn("dbo.AspNetUsers", "LockoutEnabled", c => c.Boolean(nullable: false));
    AddColumn("dbo.AspNetUsers", "AccessFailedCount", c => c.Int(nullable: false));
    AlterColumn("dbo.AspNetUsers", "UserName", c => c.String(nullable: false, maxLength: 256));
    AlterColumn("dbo.AspNetUsers", "FirstName", c => c.String(nullable: false));
    AlterColumn("dbo.AspNetUsers", "LastName", c => c.String(nullable: false));
    AddColumn("dbo.AspNetUsers", "CreatedDateTime", c => c.DateTime(nullable: false));
    AlterColumn("dbo.AspNetRoles", "Name", c => c.String(nullable: false, maxLength: 256));
    AddPrimaryKey("dbo.AspNetUserLogins", new[] { "LoginProvider", "ProviderKey", "UserId" });
    CreateIndex("dbo.AspNetUsers", "UserName", unique: true, name: "UserNameIndex");
    CreateIndex("dbo.AspNetRoles", "Name", unique: true, name: "RoleNameIndex");
    DropColumn("dbo.AspNetUsers", "Discriminator");
    }

    取自: http://adamstephensen.com/2014/05/02/upgrading-from-asp-net-identity-1-0-to-2-0/

    关于entity-framework - 迁移到 Asp.Net Identity 2.0 : new columns not being created in AspNetUsers table,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22817462/

    26 4 0