If your PostgreSQL database doesn't contain any tables related to ASP.NET Identity, then it most likely means that migrations are not enabled for ASP.NET Identity context class. In my case, I'm using VS scaffolding and I mean this class:
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
So, the first step is to run Enable-Migrations
in Package Manager Console without parameters. If you have a clean database then it will work exactly how it worked in the SO topic mentioned earlier. So if you want a simple solution then destroy your PostgreSQL database completely, create it again and simply run Enable-Migrations
.
If you don't want to destroy your PostgreSQL database or/and lose any migrations done before then just enable migrations only for ASP.NET Identity context in a separate directory. There already was a SO answer explaining how to do this.
Enable migrations in some directory (e.g. MigrationsIdentity
) for ApplicationDbContext
:
Enable-Migrations -ContextTypeName MyProject.Models.ApplicationDbContext -MigrationsDirectory MigrationsIdentity
Add initial migration for this context:
Add-Migration IdentityInitial -ConfigurationTypeName MyProject.MigrationsIdentity.Configuration
Apply this migration:
Update-Database -ConfigurationTypeName MyProject.MigrationsIdentity.Configuration
After these steps there will be ASP.NET Identity tables in your PostgreSQL database generated automatically by Code First, you don't need to run anything manually with SQL-scripts.
In the comment you've mentioned that you have separate contexts. However there is a disadvantage of multiple contexts approach: you won't use them together easily. Also you will have to specify explicitly the context with -ConfigurationTypeName
flag every time you migrate your database. I would use single context as was discussed already, but it depends on the requirements of your task.
Versions: