Skip to content
Latchkey

Rails "ActiveRecord::NoDatabaseError" in CI

ActiveRecord connected to the server but the configured database does not exist. The server is reachable; the database simply was not created in this CI run. This is deterministic.

What this error means

rails db:migrate (or boot) fails with ActiveRecord::NoDatabaseError, naming the database. It happens when db:create was skipped or the database name does not match the service.

psql
ActiveRecord::NoDatabaseError: We could not find your database: app_test.
Available database configurations are: ...
Run `bin/rails db:create` to create the database.

Common causes

Database never created

The Postgres/MySQL service did not create the named database and db:create was not run before migrating.

Name mismatch

The database in database.yml/DATABASE_URL differs from what the service created.

How to fix it

Prepare or create the database first

db:prepare creates, migrates, and seeds idempotently.

Terminal
bin/rails db:prepare RAILS_ENV=test
# or, explicitly:
bin/rails db:create db:migrate RAILS_ENV=test

Align the database name

  1. Match the database in database.yml/DATABASE_URL to the service POSTGRES_DB/MYSQL_DATABASE.
  2. Or let db:create make it so the name is whatever Rails expects.
  3. Confirm the environment (test) maps to the right database.

How to prevent it

  • Use db:prepare so the database is created before migration.
  • Keep the database name aligned across config and service env.
  • This is deterministic - retrying without creating the database fails identically.

Related guides

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