Skip to content
Latchkey

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.

.NET
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

  1. Ensure the connection string database name matches what CI creates.
  2. Run dotnet ef database update after the DB service is healthy and before tests.
  3. Alternatively call db.Database.Migrate() on startup so the app creates it.
Terminal
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.

.github/workflows/ci.yml
services:
  postgres:
    image: postgres:16
    env:
      POSTGRES_DB: app
      POSTGRES_PASSWORD: postgres

How 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.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →