When creating a new ASP.NET Core project with React and built-in authentication (IdentityServer), you can use the following command (see here for more information):

dotnet new react -o my-new-app -au Individual

This will create a new project with ASP.NET as an API backend, standard create-react-app (CRA) as the front end, and IdentityServer for authentication and authorization. However, the default database is SQLite. If you try to switch to SQL Server, you’ll run into the following error:

Entity Framework Core: Column ‘Id’ in table ‘Users’ is of a type that is invalid for use as a key column in an index

This is because the initial EF migration files were generated with SQLite data types. You will need to delete and regenerate the migration files for SQL Server.

  1. Uninstall Microsoft.EntityFrameworkCore.Sqlite
  2. Install Microsoft.EntityFrameworkCore.SqlServer
  3. Update the connection string
  4. In Startup.cs, update ConfigureServices() to use SQL Server
    services.AddDbContext<ApplicationDbContext>(options =>
  5. Remove existing migration files (because they’re meant for SQLite)
  6. Regenerate the migration files for SQL Server
    dotnet ef migrations add CreateIdentitySchema --output-dir "Data/Migrations"
  7. Run EF Migration to generate the initial tables