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=testAlign the database name
- Match the database in
database.yml/DATABASE_URLto the servicePOSTGRES_DB/MYSQL_DATABASE. - Or let
db:createmake it so the name is whatever Rails expects. - Confirm the environment (test) maps to the right database.
How to prevent it
- Use
db:prepareso 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
Rails "ActiveRecord::PendingMigrationError" in CIFix Rails "ActiveRecord::PendingMigrationError: Migrations are pending" in CI - the test database has unappli…
Postgres "FATAL: database X does not exist" in CIFix Postgres "FATAL: database X does not exist" in CI - the connection succeeded but the named database was n…
Sequelize "SequelizeConnectionRefusedError" in CIFix "SequelizeConnectionRefusedError: connect ECONNREFUSED" in CI - the database service is not ready or not…