Reputation: 252
I keep getting the error : Cannot find the object "UserRoles" because it does not exist... I want to rename the table "AspNetUserRoles" to "UserRoles". Here is my code in the OnCreating method in the Application DbContext class
builder.Entity>().ToTable("UserRoles");
Upvotes: 1
Views: 1637
Reputation: 15197
It's a little tricky for Identity because of how it use of generics.
public class ApplicationDbContext : IdentityDbContext { protected override void OnModelCreating(ModelBuilder builder) { base.OnModelCreating(builder); builder.Entity<ApplicationUser>().ToTable("Users"); builder.Entity<IdentityRole>().ToTable("Roles"); builder.Entity<IdentityUserRole<string>>().ToTable("UserRoles"); builder.Entity<IdentityUserClaim<string>>().ToTable("UserClaims"); builder.Entity<IdentityUserLogin<string>>().ToTable("UserLogins"); builder.Entity<IdentityRoleClaim<string>>().ToTable("RoleClaims"); builder.Entity<IdentityUserToken<string>>().ToTable("UserTokens"); } }
dotnet ef migrations add RenameIdentityTables
dotnet ef database update
Upvotes: 5