SQLite Error 1: 'no such table: AspNetUsers'. came from the first Identity call,
CreateAsync, against a database whose Identity tables had never been created. Create
them before Identity is used: in the lab, one EnsureCreated() call before the seed
fixed it; an app that uses migrations would apply them instead, which was not run here.
The SQLite file did not exist before the failed run and existed after it, with a size of 0 bytes, so no tables were in it.
The error
The console showed EF Core's own log lines on standard output first, with the query that failed, and then the exception on the error stream:
fail: Microsoft.EntityFrameworkCore.Database.Command[20102]
Failed executing DbCommand (6ms) [Parameters=[@normalizedUserName='?' (Size = 24)], CommandType='Text', CommandTimeout='30']
...
FROM "AspNetUsers" AS "a"
WHERE "a"."NormalizedUserName" = @normalizedUserName
LIMIT 1
...
Unhandled exception. Microsoft.Data.Sqlite.SqliteException (0x80004005): SQLite Error 1: 'no such table: AspNetUsers'.
...
Why it happens
The seed went straight to UserManager with no step that creates the schema:
...
using (var scope = app.Services.CreateScope())
{
var users = scope.ServiceProvider.GetRequiredService<UserManager<IdentityUser>>();
var user = new IdentityUser { UserName = "sofia.rossi@example.test", Email = "sofia.rossi@example.test" };
Console.WriteLine($"Create user: {await users.CreateAsync(user, "Spring-2026x")}");
}
...
The failing SQL is a SELECT on AspNetUsers by
NormalizedUserName, and the stack trace runs through
UserManager.FindByNameAsync: inside CreateAsync the user name check is the
first statement that reached the database, so it is the one that found no table. Registering the
context and Identity, as this app did, says what the tables look like; it does not create them.
The fix
...
using (var scope = app.Services.CreateScope())
{
scope.ServiceProvider.GetRequiredService<AppDb>().Database.EnsureCreated();
var users = scope.ServiceProvider.GetRequiredService<UserManager<IdentityUser>>();
...
On a new file this printed Create user: Succeeded. EnsureCreated() is
what the lab ran; it suits a test database like this one. For a database that will change over
time, create and apply an EF Core migration instead (dotnet ef migrations add and
dotnet ef database update); that path was not run in this lab. SQL Server's wording
for the same mistake was not captured here either.
How it was reproduced
A dotnet new web -f net10.0 project on .NET SDK 11.0.100 with
Microsoft.AspNetCore.Identity.EntityFrameworkCore 10.0.10 and
Microsoft.EntityFrameworkCore.Sqlite 10.0.10, Identity registered with
AddIdentityCore<IdentityUser>().AddEntityFrameworkStores<AppDb>(), and a seed in
a scope after builder.Build() that creates one fictional user. IdnLab, port 15620, AppDb,
lab.db, the user and its password are the test's; a real seed reads a password from
configuration or user-secrets, never from source. Both runs were built with
dotnet build and started with
dotnet bin\Debug\net10.0\IdnLab.dll --urls http://127.0.0.1:15620: the broken one in a
new folder where lab.db did not exist, the fixed one after the 0-byte file was moved
aside (it printed Hosting environment: Production).
Frequently asked
- Why does ASP.NET Core Identity say no such table: AspNetUsers?
- The Identity tables were never created in that database. In the lab the first CreateAsync call failed on a SELECT from AspNetUsers; calling Database.EnsureCreated() first fixed it.
- Why does the SQLite file exist if the table does not?
- In the lab lab.db did not exist before the failed run and existed after it with a size of 0 bytes, so it held no tables.
- Should I use EnsureCreated or migrations for Identity tables?
- The lab used EnsureCreated, which fits a throwaway test database. For a database that changes over time, use EF Core migrations; that path was not run in this lab.
For the migration commands, see the dotnet ef commands reference. More decoded errors in the Fixes category.