1

I'm using the database first approach for my ASP.NET MVC5 application which uses MySQL database and I'm stuck on this weird error. In my database, I have Identity tables but all in lower case like following

link to the image

but when I published the application to my staging server it gave me error like "Table 'xxx_.AspNetUsers' doesn't exist" though I have the table in my DB but it's in the lowercase(aspnetusers). And the weird part is everything works just fine locally as well as on smarterasp.net but on my staging server it's not working for some reasons.

FIXED:

protected override void OnModelCreating(System.Data.Entity.DbModelBuilder modelBuilder)
    {
        base.OnModelCreating(modelBuilder);
        //Make sure you add above line
        modelBuilder.Entity<ApplicationUser>().ToTable("aspnetusers");
        modelBuilder.Entity<IdentityRole>().ToTable("aspnetroles");
        modelBuilder.Entity<IdentityUserRole>().ToTable("aspnetuserroles");
        modelBuilder.Entity<IdentityUserClaim>().ToTable("aspnetuserclaims");
        modelBuilder.Entity<IdentityUserLogin>().ToTable("aspnetuserlogins");
        //Don't add IdentityUser ToTable aspnetusers
    }
Swar Shah
  • 143
  • 3
  • 8
  • Do hou have a connectionstring named LocalMySqlServer on your Web.config? – rkawano Sep 24 '15 at 18:48
  • @rkawano No I don't have LocalMySqlServer on my web.config I just have default connection and my DbEntities. – Swar Shah Sep 24 '15 at 18:55
  • 1
    You must configure the mapping in the OnModelCreating method of IdentityDbContext class. Take a look at http://stackoverflow.com/a/19577814/1942895 – Rafael Companhoni Sep 24 '15 at 19:06
  • @rcompanhoni Thanks buddy can you tell more specific? I did IdentityRole toTable aspnetroles and all 5 tables like that and it got rid of startup error but now i'm getting error when I try to do login saying the same thing "Table 'xxx_.AspNetUsers' doesn't exist". – Swar Shah Sep 24 '15 at 20:21

1 Answers1

1

FIXED:

protected override void OnModelCreating(System.Data.Entity.DbModelBuilder modelBuilder)
    {
        base.OnModelCreating(modelBuilder);
        //Make sure you add above line
        modelBuilder.Entity<ApplicationUser>().ToTable("aspnetusers");
        modelBuilder.Entity<IdentityRole>().ToTable("aspnetroles");
        modelBuilder.Entity<IdentityUserRole>().ToTable("aspnetuserroles");
        modelBuilder.Entity<IdentityUserClaim>().ToTable("aspnetuserclaims");
        modelBuilder.Entity<IdentityUserLogin>().ToTable("aspnetuserlogins");
        //Don't add IdentityUser ToTable aspnetusers
    }
Swar Shah
  • 143
  • 3
  • 8