How to make an int field named UserID as the primary key in AspNetUsers table in Asp.Net Core 6.0 MVC

Sherpa 326 Reputation points
2024-05-24T17:41:58.43+00:00

I am implementing Asp.Net Core Identity on an existing legacy website. I have created the Identity tables using migrations. The legacy database has a table named Users which was used for the logging. I have replaced the Users table with the AspNetUsers table. The legacy table had a field named UserID which was int as well as a primary key. I have modified the AspNetUsers table by adding a field named UserID of type int and moved all the rows from the Users table to the AspNetUsers table. The AspNetUsers table by default has ID field as the primary key which is a GUID. Is there a way to make the UserID the primary key in the AspNetUsers table?

Developer technologies | ASP.NET | ASP.NET Core
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. AgaveJoe 30,126 Reputation points
    2024-05-24T18:57:41.09+00:00

    Identity allows you to configure the primary key. The official documentation covers the details with source code.

    Change Primary Key for Users in ASP.NET Identity


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.