Reputation: 167
I am trying to add additional fields to the AspNetUsers table created by Asp.NET Identity. I am using Entity Framework and am following this guide. http://aspmvp.com/archives/37
So far I have added fields to my ApplicationUser class within IdentityModels.cs.
public class ApplicationUser : IdentityUser
{
public string FirstName { get; set; }
public string LastName { get; set; }
public int TimePlayed { get; set; }
public float RevenueGenerated { get; set; }
public string FavoriteCharity { get; set; }
public string FavoriteGame { get; set; }
public string ImageLocation { get; set; }
public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser> manager)
{
// Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType
var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);
// Add custom user claims here
return userIdentity;
}
}
I have also changed the fields needed to register in AccountController.cs, but I don't think that is going to affect how this works.
Right now I am trying to migrate the changes to my database, but for some reason the migrations being created by Add-Migration have an empty Up and empty Down. The commands I have used are:
Enable-Migrations -EnableAutomaticMigrations
Update-Database
Then I tried
Add-Migration IdentityModels
Update-Database
Both created the empty Up and Down methods in the migration. When I try to launch the site I also see that the columns don't exist, but I am assuming that is because the migration isn't occurring. Does anyone see why my changes aren't being detected.
Upvotes: 1
Views: 2414
Reputation: 101
Try adding -Force when adding the migration.
Add-Migration -configuration yourapp.migrationsfolder.Configuration migrationname-Force
Upvotes: 0
Reputation: 8436
How manay database do you have? If you are using two databases, make sure you are pointing to the right one. Enable-Migrations,Enable-Migrations -ContextTypeName DatabaseService.Models.MyDbContext
as pointed out in How do I enable EF migrations for multiple contexts to separate databases?
Also, If you are having two databases, i would suggest merging them into one,
public class MySecondDBContext : IdentityDbContext<ApplicationUser>
{
public SocialContext()
: base("DefaultConnection")
{
}
Upvotes: 1