Share via


ASP.NET Identity not creating tables.

Question

Tuesday, July 30, 2019 8:01 AM

Hi Folks,

I have created my project with "Individual Accounts" option in VS2017. 

Initially I disable (commented)  the  Configuration method in Startup.cs,  After I created  my own database and tables in SQL Server.  Now I want  Identity Framework to add Identity related tables to my newly created database.     

I have tired to update the ApplicationDbContext class  in Identity.cs under Model folder to update the database name as following

public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
    {
        public ApplicationDbContext()
            : base("MynewSite", throwIfV1Schema: false)
        {
        }

        public static ApplicationDbContext Create()
        {
            return new ApplicationDbContext();
        }
    }

Accordingly, I update the database string in web.config  

<connectionStrings>
<add name="MynewSite" connectionString="Data Source=localhost;Initial Catalog=MynewSite;Integrated Security=True" providerName="System.Data.SqlClient" />
</connectionStrings>

But I realized that It's not creating the tables inside the existing database....  I have tried enable-migrations and update-database commands on the VS2017  Console window but it didn't help.....  

Can anyone help me out with this?

All replies (1)

Tuesday, July 30, 2019 11:44 AM

jalali, the community cannot see your code.  You have to consider that we have no idea what's been done to the project or how to recover Identity at this point.

I recommend that you start over.  Populate the Identity table as illustrate in the openly documentation.  Then copy the old Entities to the new project, create a migration and update the database.

Secondly, you have not told us what framework you are implementing but a simple Google search will turn up tutorials that show how to add Identity to an existing project; ASP.NET and ASP.NET Core.

/en-us/aspnet/identity/overview/getting-started/adding-aspnet-identity-to-an-empty-or-existing-web-forms-project

/en-us/aspnet/core/security/authentication/scaffold-identity?view=aspnetcore-2.2&tabs=visual-studio