database configuration does not specify adapter

when I tried to run a command line script (let's say 'my_script' here), the same error happened. The reasons were:

  1. There is only production environment there.
  2. I missed to set RAILS_ENV for the command line.

So, the following is the solution in my case:

$ RAILS_ENV=production my_script


I just had this problem, and it was caused by a typo in my configration.yml.

I originally had this:

production:
  adapter:mysql

When I meant to have this:

production:
  adapter: mysql

That one little space between adapter: and mysql makes the difference.


Another possible cause:

In Rails 3.2.x, establish_connection has a default argument set from the environment:

From connection_specification.rb:

def self.establish_connection(spec = ENV["DATABASE_URL"])
  resolver = ConnectionSpecification::Resolver.new spec, configurations
  spec = resolver.spec

The way ConnectionSpecification::Resolver works depends on ENV['DATABASE_URL'] giving a nil if not set. (Normally, it would be something like 'postgres://...').

So, if you happen to have misconfigured DATABASE_URL such that ENV['DATABASE_URL'] == '', that will give you database configuration does not specify adapter.


I had this error when I mistakenly started rails server with

sudo rails s -e "Production" -p 80

and I should have started rails with

sudo rails s -e "production" -p 80


I found another thing that can cause this problem: "mixing in" another YAML node using & and *.

I was originally doing something like the following to facilitate local, per-develop, Git-ignored config files:

http://blog.lathi.net/articles/2006/03/02/config-database-yml-goodness-for-teams

But, after some debugging, I came to find out that establish_connection was for some reason being called with only the mixed-in key-value pairs and not the main ones. I.e. adapter, host, and database were not being passed in. I have no idea why, and this used to work for me.

Anyhow, instead of mixing in another YAML node, I now put the entire development and test hashes in the local config file, and establish_connection is once again being called correctly.