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.
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 file Both the Up() and Down() methods were empty.
public partial class V023 : DbMigration
{
public override void Up()
{
}
public override void Down()
{
}
}
Tried the solution proposed by user1502551 but it gave me issues and didn't include the Down() method. The problems I was having was that the indexes being altered didn't exist by default from Identity 1.0 and there were a couple of extra columns that 2.0/2.1 doesn't expect (namely First and Last Name fields). Full Up() and Down() here:
public override void Up()
{
RenameColumn(table: "dbo.AspNetUserClaims", name: "User_Id", newName: "UserId");
AddColumn("dbo.AspNetUsers", "Email", c => c.String());
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));
DropColumn("dbo.AspNetUsers", "Discriminator");
}
public override void Down()
{
AddColumn("dbo.AspNetUsers", "Discriminator", c => c.String(nullable: false, maxLength: 128));
AlterColumn("dbo.AspNetUsers", "UserName", c => c.String(nullable: true));
DropColumn("dbo.AspNetUsers", "AccessFailedCount");
DropColumn("dbo.AspNetUsers", "LockoutEnabled");
DropColumn("dbo.AspNetUsers", "LockoutEndDateUtc");
DropColumn("dbo.AspNetUsers", "TwoFactorEnabled");
DropColumn("dbo.AspNetUsers", "PhoneNumberConfirmed");
DropColumn("dbo.AspNetUsers", "PhoneNumber");
DropColumn("dbo.AspNetUsers", "EmailConfirmed");
DropColumn("dbo.AspNetUsers", "Email");
RenameColumn(table: "dbo.AspNetUserClaims", name: "UserId", newName: "User_Id");
}
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/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With