I\'m following the documentation for using Identity and am trying register a new user (executing the register action), but it fails with the following error:
I found the problem. My ApplicationContext was inheriting from DbContext. I changed it to IdentityDbContext<ApplicationUser> and it works.
Create new context class which inherit IdentityDbContext.
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
: base(options)
{
}
protected override void OnModelCreating(ModelBuilder builder)
{
base.OnModelCreating(builder);
// Customize the ASP.NET Identity model and override the defaults if needed.
// For example, you can rename the ASP.NET Identity table names and more.
// Add your customizations after calling base.OnModelCreating(builder);
}
}
and in startup.cs file add below code
services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(connection));
This will help you for database first approach.