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:prepareAlign names and credentials
- Make config/database.yml test database name match what the CI service exposes (or use DATABASE_URL).
- Set host/port/user/password to the CI service values via env.
- 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
ActiveRecord::PendingMigrationError in CIFix "ActiveRecord::PendingMigrationError: Migrations are pending" in CI - the test database schema is behind…
PG::ConnectionBad could not connect to server in CIFix "PG::ConnectionBad: could not connect to server" in Rails CI - Postgres was not reachable when tests conn…
ActiveRecord::StatementInvalid in CIFix "ActiveRecord::StatementInvalid" in CI - a SQL statement failed (undefined column/table, type mismatch, o…