【发布时间】:2018-07-25 20:59:11
【问题描述】:
我有一个托管在 Azure 中的 mysql 数据库,并且我的计算机上有 MVC 应用程序。 我想使用 Identity 框架来跟踪我的用户。身份表是在我的数据库中生成的,但它们的名称都错误:
因为当我想在我的注册页面上添加新用户时,我收到以下错误:
表 xxxxxxxx.aspnetusers 不存在。
我知道这是因为我的表名错误。 但我不知道为什么添加的表格名称为 my_aspnet_users 而不是 aspnetusers。
我按照这篇文章作为指导: https://www.codeproject.com/Tips/788357/How-to-set-up-application-using-ASP-NET-Identity-w
我还尝试编辑我的 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");
}
}
【问题讨论】:
-
您是否尝试使用实际的表名进行配置,例如
modelBuilder.Entity<IdentityUser>().ToTable("my_aspnet_users");?其他表也类似。 -
这不起作用,因为它不会像现在一样重命名表。所以如果我改变它,它会保持不变。但我会尝试确定。
-
这不是为了重命名表格,而是让
EntityFramework DbContext知道要使用哪些表格,有替代名称。 -
确实有效,如果您愿意,可以发布答案,我会批准
标签: c# mysql asp.net asp.net-mvc identity