Skip to content
Latchkey

ActiveRecord::NoDatabaseError for the test database in CI

Rails connected to the database server but the named test database does not exist. The server is reachable; the database itself was never created on the runner.

What this error means

Boot or test setup fails with NoDatabaseError naming the test database. Distinct from a connection failure: the server answered, the database is just absent.

rails
ActiveRecord::NoDatabaseError: We could not find your database: myapp_test.
Available database configuration can be found in config/database.yml.
To resolve this issue:
- Did you create the database? Run `bin/rails db:create`.

Common causes

Database never created in CI

The job started the DB service but did not run db:create for the test database.

Name mismatch with the service

database.yml names a database the CI service did not provision under that exact name.

Wrong environment

db:create ran for development, leaving the test database missing.

How to fix it

Create and prepare the test database

Terminal
RAILS_ENV=test bin/rails db:create db:schema:load
# or the one-shot:
RAILS_ENV=test bin/rails db:prepare

Align names and credentials

  1. Make config/database.yml test database name match what the CI service exposes (or use DATABASE_URL).
  2. Set host/port/user/password to the CI service values via env.
  3. Run db:create before any migration or test step.

How to prevent it

  • Run db:create (or db:prepare) for RAILS_ENV=test in CI setup.
  • Drive config from DATABASE_URL to avoid name drift.
  • Order setup so the DB exists before tests.

Related guides

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