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
    }
4
  • Do hou have a connectionstring named LocalMySqlServer on your Web.config? Commented Sep 24, 2015 at 18:48
  • @rkawano No I don't have LocalMySqlServer on my web.config I just have default connection and my DbEntities. Commented Sep 24, 2015 at 18:55
  • 1
    You must configure the mapping in the OnModelCreating method of IdentityDbContext class. Take a look at stackoverflow.com/a/19577814/1942895 Commented Sep 24, 2015 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". Commented Sep 24, 2015 at 20:21

1 Answer 1

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
    }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.