ASP.NET Identity using a MySQL Database gives my identity tables a wrong name

Multi tool use
Multi tool use
The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP


ASP.NET Identity using a MySQL Database gives my identity tables a wrong name



I have a mysql database hosted in Azure, and I have MVC application om my computer.
I wanted to use the Identity framework to keep track of my users. The identity tables got generated in my database, but they all have wrong names:



enter image description here



because when i want to add a new user on my register page i get the following error:



Table xxxxxxxx.aspnetusers doesnt exist.



I know this is because my table names are wrong.
But i have no clue why the tables got added with the name my_aspnet_users in stead of aspnetusers.



I followed this article as a guide:
https://www.codeproject.com/Tips/788357/How-to-set-up-application-using-ASP-NET-Identity-w



I also tried to edit my ApplicationDbContext:


public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{

public ApplicationDbContext()
: base("WebShopDatabaseContext")
{
Database.SetInitializer(new MySqlInitializer());
}

public static ApplicationDbContext Create()
{
return new ApplicationDbContext();
}
protected override void OnModelCreating(System.Data.Entity.DbModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);

modelBuilder.Entity<IdentityUser>().ToTable("aspnetusers");
modelBuilder.Entity<ApplicationUser>().ToTable("aspnetusers");
modelBuilder.Entity<IdentityUserRole>().ToTable("aspnetuserroles");
modelBuilder.Entity<IdentityUserLogin>().ToTable("aspnetuserlogins");
modelBuilder.Entity<IdentityUserClaim>().ToTable("aspnetuserclaims");
modelBuilder.Entity<IdentityRole>().ToTable("aspnetroles");
}
}





Did you try configure with the actual table names, like modelBuilder.Entity<IdentityUser>().ToTable("my_aspnet_users");? And similar for other tables.
– pfx
yesterday




modelBuilder.Entity<IdentityUser>().ToTable("my_aspnet_users");





This wouldn't work because it doesn't rename the tables as it is now. So if i would change that it would stay te same. But il try it to be sure.
– JoaVer
yesterday





It is not for the purpose of renaming the tables, it is to let the EntityFramework DbContext know which tables to use, having alternative names.
– pfx
yesterday




EntityFramework DbContext





that acctually worked, if you want you can post an answer and i will aprove it
– JoaVer
yesterday




1 Answer
1



I'm not going to try to figure out why your table names are as-is,
but you can configure your DbContext to use the actual ones,
like here below.
Do the same for each table.


DbContext


modelBuilder.Entity<IdentityUser>().ToTable("my_aspnet_users");






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Te10 uxzzi i4ez QVTTte76LGL8WcG0knL5flaKHe,9i fm2MnhLmfyPZJYYGT0bokUCShRHb2t70PobUnFQycKF5KB5OcG4CscGPH
pPBywoqOvNb,WUfY5DW,B JLB0tjqmRN8tl 4z,L A,xq,aooq6,Jjn21,heD09TsLZ CFvA,2dX sy5C Ois87jfZR

Popular posts from this blog

Keycloak server returning user_not_found error when user is already imported with LDAP

PHP parse/syntax errors; and how to solve them?

415 Unsupported Media Type while sending json file over REST Template