本文介绍了迁移到Asp.Net 2.0身份:不是正在AspNetUsers表中创建新列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到以下错误,当我尝试注册一个新用户,使用Identity 2.0和默认的MVC 5应用程序:

 无效的列名电子邮件。
无效的列名称EmailConfirmed。
无效的列名称******中国。
无效的列名称PhoneNumberConfirmed。
无效的列名称TwoFactorEnabled。
无效的列名称LockoutEndDateUtc。
无效的列名称LockoutEnabled。
无效的列名称AccessFailedCount。
(重复2次以上,我一共在AspNetUsers表4的测试用户。)

我有一个小的应用程序我刚从MVC4 /身份1.0 MVC5 /身份升级2.0,所以我有标识1.0列(用户名,PasswordHash,SecurityStamp,鉴)工作。


  • 我是使用远程托管SQL2012数据库的标准身份1.0表。

  • 我创建了一个干净的项目,注册一个用户,它运行在的LocalDB罚款。

  • 我成功运行添加迁移初始和更新数据库在我的远程数据库。

  • 我最初跟着本官方指南和步骤5中的code没有被生成。我试着用手工粘贴跑更新数据库-verbose了。似乎成功完成,但仍然得到错误。

鸭preciate任何帮助!

迁移和configuration.cs文件

 内部密封类配置:DbMigrationsConfiguration< FactBanker.Models.ApplicationDbContext>
{
    公共配置()
    {
        AutomaticMigrationsEnabled = TRUE;
    }    保护覆盖无效的种子(FactBanker.Models.ApplicationDbContext上下文)
    {    }
}

}

我的V023 migration.cs文件
无论是向上()和向下()方法是空的。

 公共部分类V023:DbMigration
{
    公共覆盖无效向上()
    {    }    公共覆盖无效向下()
    {    }
}


解决方案

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

 公共覆盖无效向上()
{
    RenameColumn(表:dbo.AspNetUserClaims,名称:USER_ID了newName:用户ID);
    RenameIndex(表:dbo.AspNetUserClaims,名称:IX_User_Id了newName:IX_UserId);
    DropPrimaryKey(dbo.AspNetUserLogins);
    AddColumn(dbo.AspNetUsers,电子邮件,C = GT; c.String(最大长度:256));
    AddColumn(dbo.AspNetUsers,EmailConfirmed,C = GT; c.Boolean(可空:FALSE));
    AddColumn(dbo.AspNetUsers,******中国中,c => c.String());
    AddColumn(dbo.AspNetUsers,PhoneNumberConfirmed,C = GT; c.Boolean(可空:FALSE));
    AddColumn(dbo.AspNetUsers,TwoFactorEnabled,C = GT; c.Boolean(可空:FALSE));
    AddColumn(dbo.AspNetUsers,LockoutEndDateUtc中,c => c.DateTime());
    AddColumn(dbo.AspNetUsers,LockoutEnabled,C = GT; c.Boolean(可空:FALSE));
    AddColumn(dbo.AspNetUsers,AccessFailedCount,C = GT; c.Int(可空:FALSE));
    AlterColumn(dbo.AspNetUsers,用户名,C = GT; c.String(可空:假的,最大长度:256));
    AlterColumn(dbo.AspNetUsers,名字,C = GT; c.String(可空:FALSE));
    AlterColumn(dbo.AspNetUsers,姓氏,C = GT; c.String(可空:FALSE));
    AddColumn(dbo.AspNetUsers,CreatedDateTime,C = GT; c.DateTime(可空:FALSE));
    AlterColumn(dbo.AspNetRoles,姓名,C = GT; c.String(可空:假的,最大长度:256));
    AddPrimaryKey(dbo.AspNetUserLogins,新的[] {LoginProvider,ProviderKey,用户ID});
    的CreateIndex(dbo.AspNetUsers,用户名,独一无二的:真正的,名称:UserNameIndex);
    的CreateIndex(dbo.AspNetRoles,姓名,独一无二的:真正的,名称:RoleNameIndex);
    DropColumn(dbo.AspNetUsers,鉴别);
}

来自的

I get the following error when I try to register a new user, using Identity 2.0 and the default MVC 5 application:

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.)

I have a small application I've just upgraded from MVC4/Identity 1.0 to MVC5/Identity 2.0, so I had the Identity 1.0 columns (UserName, PasswordHash, SecurityStamp, Discriminator) working.

  • I'm was using a remotely hosted SQL2012 DB with the standard Identity 1.0 tables.
  • I created a 'clean' project, registered a user and it ran fine on the localDB.
  • I successfully ran 'add-migration initial' and 'update-database' on my remote database.
  • I initially followed this official guide , and the code in step 5 wasn't being generated. I tried pasting it in by hand and ran "update-database -verbose" again. Seemed to complete successfully, but still get the error.

Appreciate any help!

migration and configuration.cs files

internal sealed class Configuration : DbMigrationsConfiguration<FactBanker.Models.ApplicationDbContext>
{
    public Configuration()
    {
        AutomaticMigrationsEnabled = true;
    }

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

    }
}

}

My V023 migration.cs fileBoth the Up() and Down() methods were empty.

public partial class V023 : DbMigration
{
    public override void Up()
    {

    }

    public override void Down()
    {

    }
}
解决方案

I was having the same problem. I used this manual migration and I haven't run into any additional issues yet.

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");
}

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

这篇关于迁移到Asp.Net 2.0身份:不是正在AspNetUsers表中创建新列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 02:22