0

I am using code first migrations and trying to merge databases (default, and FlavorPingRebuild), and the ApplicationUser table is not being added to the merged DB. I am unsure of why the table is not being added.

namespace FlavorPingRebuild.Models
{
    public class FlavorPingRebuildContext : IdentityDbContext
    {
        public FlavorPingRebuildContext() : base("name=FlavorPingRebuildContext")
        {
        }

        public System.Data.Entity.DbSet<FlavorPingRebuild.Models.Merchant> Merchants { get; set; }

        public System.Data.Entity.DbSet<FlavorPingRebuild.Models.MenuItem> MenuItems { get; set; }

        public DbSet<IdentityUserLogin> UserLogins { get; set; }
        public DbSet<IdentityUserClaim> UserClaims { get; set; }
        public DbSet<IdentityUserRole> UserRoles { get; set; }
        public DbSet<ApplicationUser> ApplicationUsers { get; set; }

        protected override void OnModelCreating(DbModelBuilder builder)
        {
            //removes plural naming in DB tables
            builder.Conventions.Remove<PluralizingTableNameConvention>();

            //Removes cascade deletes.
            builder.Conventions.Remove<OneToManyCascadeDeleteConvention>();

            //When DB is created need to set up foreign key relationships.
            builder.Entity<IdentityUserLogin>().HasKey<string>(l => l.UserId);
            builder.Entity<IdentityRole>().HasKey<string>(r => r.Id);
            builder.Entity<IdentityUserRole>().HasKey(r => new { r.RoleId, r.UserId });
        }
    }
}
CodeNotFound
  • 22,153
  • 10
  • 68
  • 69
JP Hochbaum
  • 637
  • 4
  • 15
  • 28
  • What you are setting the HasKey for those classes? There are already done by IndeityDbContext class. Remove them and see what happened. – CodeNotFound Feb 08 '16 at 21:06
  • I put that there because I was experiencing this: http://stackoverflow.com/questions/28531201/entitytype-identityuserlogin-has-no-key-defined-define-the-key-for-this-entit – JP Hochbaum Feb 08 '16 at 21:08
  • Chekc the answer of that link and you will see that what you are doing is incorrect – CodeNotFound Feb 08 '16 at 21:09
  • Well I don't want that exact same build.... – JP Hochbaum Feb 08 '16 at 21:18
  • I also have my app context inheriting from IdentityDbContext. I don't have any DbSets or OnModelCreating code because that is handled automatically by the base class. Try removing all the identity db sets and modeling code and the next migration should generate code to create the identity objects. Then you can restore or seed() as needed. – Steve Greene Feb 09 '16 at 17:24

0 Answers0