1

I'm attempting to setup store for my IdentityServer4 Token server, I'm following along with this tutorial where I encountered database migrations like so:

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

Apparently I'm running a different version of powershell, or the tools are messed up so I have to run my migrations using a different syntax

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

Theese two commands worked great however I'm still missing the third command to generate the ApplicationDbContext:

When I run I get this exception:

SqlException: Invalid object name 'AspNetUsers'.

I'm missing this table along with a few others from the database for Identity, does anyone know which Migration to use?

johnny 5
  • 19,893
  • 50
  • 121
  • 195

2 Answers2

1

If you create the default ASP.NET project with authentication, you will see a migration file 00000000000000_CreateIdentitySchema.cs.

So

dotnet ef migrations add CreateIdentitySchema -c ApplicationDbContext

should work.

adeptus
  • 35
  • 1
  • 5
0

It turns out it was simple. I though Migrations were generating the Db from something that it had in code, but in actuality it seems to be constructing the database based off of the CLR Class configuration

Add-Migration InitialStillDontKnowWhatThisNameIsFor -c ApplicationDbContext -o Data/Migrations/IdentityServer/PersistedGrantDb

I don't know what the names is for but that will generate the DB

johnny 5
  • 19,893
  • 50
  • 121
  • 195