gpt4 book ai didi

asp.net - 重命名 dbo.AspNetUsers 表

转载 作者:行者123 更新时间:2023-12-04 02:23:03 38 4
gpt4 key购买 nike

我正在尝试重命名由 ASP.net Identity 2.0 生成的默认表名。我阅读了所有关于 stackoverflow 的文章、问题和答案,但我仍然遇到同样的错误。

我将这些表重命名为 Roles、UserClaims、Logins、UserRoles 和 Users。我还将应用程序 dbcontext 更改为以下内容

public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
public ApplicationDbContext()
: base("DefaultConnection", throwIfV1Schema: false)
{
}

public static ApplicationDbContext Create()
{
return new ApplicationDbContext();
}

protected override void OnModelCreating(System.Data.Entity.DbModelBuilder modelBuilder) {
base.OnModelCreating(modelBuilder);


modelBuilder.Entity<IdentityUser>().ToTable("Users", "dbo");
modelBuilder.Entity<IdentityRole>().ToTable("Roles", "dbo");
modelBuilder.Entity<IdentityUserRole>().ToTable("UserRoles", "dbo");
modelBuilder.Entity<IdentityUserClaim>().ToTable("UserClaims", "dbo");
modelBuilder.Entity<IdentityUserLogin>().ToTable("UserLogins", "dbo");

}

}

但我一直收到 Invalid object name 'dbo.AspNetUsers'.错误,我不知道为什么它仍然试图首先定位 AspNetUsers 而不仅仅是用户,尽管我进行了上述更改。这下彻底绝望了。

enter image description here

数据库也是如此,具有新表名的相同列:

enter image description here

和 SQL 数据库项目:

enter image description here

最佳答案

您需要更新数据库。 Enable-MigrationsUpdate-Database ,详细解释here . EF 代码优先方法的重点是编写我们的模型类和配置,每次我们更改某些内容时,我们都会使用 EF 迁移来更新数据库架构。

解释了使用 asp.net-identity-entityframework 的数据库优先方法 herehere ,没那么简单

关于asp.net - 重命名 dbo.AspNetUsers 表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28015771/

38 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com