How to create identity tables in an already created database using code first? c# entity-framework


My application has been in development for about a month. I now decided to use ASP.NET Identity. I already have the view models for identity but need to create the tables. I was thinking and I am not exactly sure why I do not have the tables already if I have the view models?? I have drop create on in the initializer with my own custom context, I just need to know how to get EF to build the included Identity tables for users and roles? I looked around and none of the posted answers seem to be what I need?

4/17/2017 8:59:37 PM

Accepted Answer

So after a bit of reading a fiddling i got the answer. All I had to do was finally run the register method from ASP.NET Identity and all the tables were created.

4/18/2017 3:33:31 PM

Popular Answer

Consider Migrations

If applicable, you need to consider building a migration, which will allow you to generate (and potentially execute) the necessary scripts to create the appropriate tables or changes within your database.

By default, you should have some type of ApplicationDbContext class that looks like the following which will be used to define your "security-related" database:

public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
    public ApplicationDbContext()
        : base("DefaultConnection", false)

    // Other code omitted for brevity

You'll then just need to run the Enable-Migrations command in Package Manager Console:


This should generate a Migrations folder within your application that contains various configuration files that control how migrations are preformed as well as an InitialCreate migration. This may only be present if you previously had some Code-First related code within your application, if not, don't worry about it. You can then try running the Update-Database command, which should execute any migrations (including an initial one) against your database:


Once your database has been updated, you can continue to make changes to your model and simply create and execute new migrations through the Add-Migration command and the previous Update-Database command:

Add-Migration "AddedAnotherPropertyToFoo"

Related Questions


Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow