简体   繁体   English

ASP.NET MVC 身份数据库表映射问题

[英]ASP.NET MVC identity database table mapping issue

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.我正在为我的 ASP.NET MVC5 应用程序使用数据库优先方法,该应用程序使用 MySQL 数据库,但我遇到了这个奇怪的错误。 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).但是当我将应用程序发布到我的登台服务器时,它给了我类似“表'xxx_.AspNetUsers'不存在”的错误,尽管我的数据库中有该表但它是小写的(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.奇怪的是,在本地和 smarterasp.net 上一切正常,但在我的临时服务器上,由于某些原因,它无法正常工作。

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
    }

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
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM