EF Core "database ... does not exist" in CI
The provider connected to the server but the target database has not been created yet. dotnet ef database update (or Database.Migrate()) creates it, but only if it runs before the app queries tables.
What this error means
A test or migration fails with Npgsql "3D000: database \"app\" does not exist" or SQL Server "Cannot open database \"app\" requested by the login." while the server itself is reachable.
Npgsql.PostgresException (0x80004005): 3D000: database "app" does not exist
at Npgsql.NpgsqlConnector.<Open>...Common causes
The database was never created in CI
A service container starts the server with a default database, but your connection string names a different database that nothing created.
The app queries before migrations run
The app or test hits the schema before database update / Migrate() created the database and tables.
How to fix it
Create the database via migrations before use
- Ensure the connection string database name matches what CI creates.
- Run
dotnet ef database updateafter the DB service is healthy and before tests. - Alternatively call
db.Database.Migrate()on startup so the app creates it.
dotnet ef database update --connection "$ConnectionStrings__Default"Match the service container database name
Set the postgres service to create the same database your connection string uses.
services:
postgres:
image: postgres:16
env:
POSTGRES_DB: app
POSTGRES_PASSWORD: postgresHow to prevent it
- Keep the connection-string database name consistent with the CI service container.
- Run migrations after the DB is healthy and before the app queries it.
- Use Database.Migrate() on startup for test hosts so the schema always exists.