问题
I've followed the Rails Tutorial up to the linked point.
Here's the shell output:
jrhorn424 at hook in ~/Learning/rails/rails-tutorial/demo_app on master
$ heroku run rake db:migrate
Running rake db:migrate attached to terminal... up, run.2
### Snip ###
Migrating to CreateUsers (20120310145100)
Migrating to CreateMicroposts (20120311052021)
rake aborted!
database configuration does not specify adapter
Tasks: TOP => db:schema:dump
(See full trace by running task with --trace)
I've consulted the Heroku quick start, and done a bit of Googling. I suspected the problem was with config/database.yml
since that is full of references to sqlite3
in my development environment. However, on the server, the same file includes these lines, among others:
adapter = uri.scheme
adapter = "postgresql" if adapter == "postgres"
Adding data through the deployed application succeeds, but running heroku run rake db:migrate
still fails.
Here's my Gemfile:
source 'https://rubygems.org'
gem 'rails', '3.2.2'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
group :development do
gem 'sqlite3', '1.3.5'
end
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'sass-rails', '3.2.4'
gem 'coffee-rails', '3.2.2'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer'
gem 'uglifier', '1.2.3'
end
gem 'jquery-rails', '2.0.0'
group :production do
gem 'pg', '0.12.2'
end
回答1:
I would recommend dropping your databases with:
bundle exec rake db:drop:all
If you are going to be hosting on heroku, go ahead and use postgres for all of your environments. Delete the sqlite gem and just include
gem 'pg'
near the top of your Gemfile.
Peform a:
bundle
bundle exec rake db:create
bundle exec rake db:migrate
Try to commit and push again (you know how to do that already).
Let me know if that doesn't work.
PS, here is what my database.yml file looks like:
# PostgreSQL v0.8.x
# gem install pg
development:
adapter: postgresql
encoding: unicode
host: localhost
database: health_development
pool: 5
username: volpine
password: password
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
adapter: postgresql
encoding: unicode
host: localhost
database: health_test
pool: 5
username: volpine
password: password
production:
adapter: postgresql
encoding: unicode
host: localhost
database: health_production
pool: 5
username: volpine
password: password
回答2:
For me i faced this error when i tried to open rails console in production,
When i gave,
bundle exec rails c RAILS_ENV=production
it throws the error
`resolve_hash_connection': database configuration does not specify adapter (ActiveRecord::AdapterNotSpecified)
but it works when i gave,
RAILS_ENV=production bundle exec rails c
回答3:
I ran into this and found that manually setting RAILS_ENV did the trick for me:
heroku run RAILS_ENV=production rake db:migrate
回答4:
When I ran heroku db:push
, I got a taps error that lead me to switch to using ruby 1.9.2. After switching versions and starting a new app, I no longer receive the error from heroku run rake db:migrate
, and everything works as expected.
Update: I've just been informed that version mismatching shouldn't matter for db:migrate
. It definitely mattered for db:push
, so I'm not sure what was wrong. In any case, when I initialize a new app with the same Gemfile and 1.9.2, it works.
回答5:
I had the same problem. It was happening because I removed the RAILS_ENV environment variable from my heroku app and only left a RACK_ENV one.
Adding the RAILS_ENV=production did fix the issue:
heroku config:add RAILS_ENV=production --app XXXX-production
回答6:
Heroku doesn't look at your database.yml file, it looks at DATABASE_URL - if that's not set, or there is a typo in it, then you'll get that error.
来源:https://stackoverflow.com/questions/9661115/on-heroku-rake-dbmigrate-fails-with-database-configuration-does-not-specify-a