I have been following this book on how to Add Identity to an existing project (specifically section 14.4). I have done the following
- Added the ASP.NET Core Identity NuGet packages
- Configured Startup to use Authentication Middleware and added Identity services to the DI container
- Updated the EF Core data model with the Identity entities
Code for updating the EF Core data model to support Identity
namespace Hoook.Data
{
public class HoookDbContext : IdentityDbContext<ApplicationUser>
{
public HoookDbContext(DbContextOptions<HoookDbContext> options) : base(options)
{
}
public DbSet<Venture> Ventures { get; set; }
}
}
Code for custom user type which inherits from IdentityUser
namespace Hoook.Data
{
public class ApplicationUser : IdentityUser
{
}
}
Startup.cs code for adding Identity service to DI
services.AddDefaultIdentity<ApplicationUser>(options =>
options.SignIn.RequireConfirmedAccount = true).AddEntityFrameworkStores<HoookDbContext>();
Now I have then ran the following command in VSCode
dotnet ef migrations add AddIdentitySchema
Then I ran dotnet ef database update
At this point I am to assume my database is updated and contains the Identity tables, but that is incorrect. How Am I to add the Identity tables to my existing database? I have searched through these 1, 2, 3 stackoverflow questions with no luck.
Adding a screenshot of my SSMS Migration History and tables. The migration took but no Identity tables have been populated.
UPDATE
It may help to note, I have created an Identity app using the .NET Core CLI with new webapp -au Indi- vidual -uld
. Inside the migrations of that app after running dotnet ef database update
, the Migrations up and down methods are actually populated. However in my app when adding the migration following the above steps, my Migration file looks as so:
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Hoook.Migrations
{
public partial class AddIdentitySchema : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
}
protected override void Down(MigrationBuilder migrationBuilder)
{
}
}
}