Another option may be to subclass Microsoft.AspNet.Identity.EntityFramework.IdentityDbContext<Models.ApplicationUser>, this obviously will only apply when you are not already subclassing another DbContext-derived type.
For example:
public class MyDbContext : IdentityDbContext<ApplicationUser>, IMyDbContext
{
public IDbSet<MyOtherEntity> OtherEntities { get; set; }
public MyDbContext() : base("MyDb", false)
{
Database.SetInitializer<MyDbContext>(null);
}
public static DbContext Create()
{
return new MyDbContext();
}
}
You will need to edit Startup.Auth.cs and update the app.CreatePerOwinContext call to instead refer to the Create() method of your new DbContext type (or whatever DI-based allocator you're already using in your established, mature products.) Just keep in mind that the type returned by the method you provide here is the type used for future Owin context Get() calls.
Thus, you will also need to edit IdentityConfig.cs to instead refer to the MyDbContext type (instead of ApplicationDbContext). Otherwise this method will fail. If, after editing, you get a null reference exception here then you have not properly edited Startup.Auth.cs (see last paragraph.)
You will also be wise to comment-out the default scaffold ApplicationDbContext located in IdentityModels.cs so other developers don't become confused in the future, it should also help you identify any lingering references (there shouldn't be any.)
The above should be sufficient for most common cases, in cases where your existing DB schema differs from what would be generated by default you can override OnModelCreating as outlined in the accepted answer from @pwdst (in addition to what is detailed above.)
IdentityDbContextis that you can only have one migration-enabled dbcontext per project, and if you already have a DbContext this new IdentityDbContext is in conflict. Mapping to our schema isn't really a solid/valid solution, it only applies in the simplest of scenarios. What we need is an identity framework that does not dictate DbContext -- For example; the current version of IdentityDbContext should be interface based, instead allocators throughout the codebase currently rely on the concrete IdentityDbContext type. Unnecessarily. For shame.