I'm using ASP.NET Core 3.1 with a MySql database and Entity Framework Core. I need to add identity to this project.
I've added this packages:
- Pomelo.EntityFrameworkCore.MySql
- Microsoft.EntityFrameworkCore
- Microsoft.AspNetCore.Identity
- Microsoft.AspNetCore.Identity.UI
- Microsoft.AspNetCore.Identity.EntityFrameworkCore
I've created an ApplicationDbContext:
public class ApplicationDbContext : IdentityDbContext
{
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
: base(options)
{
}
}
And add following code to the Startup file in the ConfigurateServices method:
services.AddDbContext<ApplicationDbContext>(options =>
options.UseMySql(
Configuration.GetConnectionString("DefaultConnection")));
services.AddDefaultIdentity<IdentityUser>(options => options.SignIn.RequireConfirmedAccount = true)
.AddEntityFrameworkStores<ApplicationDbContext>();
Also I added a DefaultConnection to appsetings.json.
The last step in all tutorials is to recreate Migrations and here I got an error.
No migrations configuration type was found in the assembly 'Web'. (In Visual Studio you can use the Enable-Migrations command from Package Manager Console to add a migrations configuration).
And If I run 'Enable-Migrations' I get
No context type was found in the assembly 'Web'
How could I run migrations and update database?