ApplicationDBContext AspUsers 迁移命令

ApplicationDBContext AspUsers Migration command

我正在尝试为我的 IdentityServer4 令牌服务器设置商店, 我跟着这个 tutorial 遇到了这样的数据库迁移:

dotnet ef migrations add InitialIdentityServerMigration -c PersistedGrantDbContext
dotnet ef migrations add InitialIdentityServerMigration -c ConfigurationDbContext
dotnet ef migrations add InitialIdentityServerMigration -c ApplicationDbContext

显然我 运行 正在使用不同版本的 powershell,或者工具被搞砸了所以我必须 运行 我的迁移使用不同的语法

Add-Migration InitialIdentityServerPersistedGrantDbMigration -c PersistedGrantDbContext -o Data/Migrations/IdentityServer/PersistedGrantDb
Add-Migration InitialIdentityServerConfigurationDbMigration -c ConfigurationDbContext -o Data/Migrations/IdentityServer/ConfigurationDb

这两个命令效果很好,但是我仍然缺少生成 ApplicationDbContext 的第三个命令:

当我 运行 我得到这个异常:

SqlException: Invalid object name 'AspNetUsers'.

我缺少这个 table 以及数据库中的其他一些身份信息,有人知道要使用哪个迁移吗?

原来很简单。我虽然 Migrations 是从它在代码中的东西生成 Db,但实际上它似乎是基于 CLR Class 配置

构建数据库
Add-Migration InitialStillDontKnowWhatThisNameIsFor -c ApplicationDbContext -o Data/Migrations/IdentityServer/PersistedGrantDb

我不知道名称的用途,但这会生成数据库

如果您使用身份验证创建默认 ASP.NET 项目,您将看到一个迁移文件 00000000000000_CreateIdentitySchema.cs

所以

dotnet ef migrations add CreateIdentitySchema -c ApplicationDbContext

应该可以。