![](/img/trans.png)
[英]rake db:test:clone RAILS_ENV=“test” fails, Odd Error: database configuration does not specify adapter
[英]On heroku, rake db:migrate fails with “database configuration does not specify adapter”
我已經按照Rails教程進行了鏈接。
這是shell輸出:
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)
我已經咨詢了Heroku的快速啟動 ,並完成了一些谷歌搜索。 我懷疑問題出在config/database.yml
因為在我的開發環境中它充滿了對sqlite3
的引用。 但是,在服務器上,同一文件包括以下行:
adapter = uri.scheme
adapter = "postgresql" if adapter == "postgres"
通過已部署的應用程序添加數據成功,但運行heroku run rake db:migrate
仍然失敗。
這是我的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
對我來說,當我嘗試在生產中打開rails控制台時遇到此錯誤,
當我給,
bundle exec rails c RAILS_ENV=production
它會引發錯誤
`resolve_hash_connection': database configuration does not specify adapter (ActiveRecord::AdapterNotSpecified)
但它給我的作用,
RAILS_ENV=production bundle exec rails c
我建議刪除你的數據庫:
bundle exec rake db:drop:all
如果您要在heroku上主持,請繼續使用postgres來處理所有環境。 刪除sqlite gem並只包含
gem 'pg'
靠近Gemfile的頂部。
執行a:
bundle
bundle exec rake db:create
bundle exec rake db:migrate
嘗試再次提交並推送(你知道該怎么做)。
如果這不起作用,請告訴我。
PS,這是我的database.yml文件的樣子:
# 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
我遇到了這個,發現手動設置RAILS_ENV對我來說很有用:
heroku run RAILS_ENV=production rake db:migrate
我有同樣的問題。 它發生了,因為我從我的heroku應用程序中刪除了RAILS_ENV環境變量,只留下了一個RACK_ENV。
添加RAILS_ENV =生產確實解決了問題:
heroku config:add RAILS_ENV=production --app XXXX-production
Heroku不查看你的database.yml文件,它查看DATABASE_URL - 如果沒有設置,或者里面有拼寫錯誤,那么你就會得到那個錯誤。
當我運行heroku db:push
,我得到了一個水龍頭錯誤 ,導致我切換到使用ruby 1.9.2。 切換版本並啟動新應用程序后,我不再收到來自heroku run rake db:migrate
的錯誤,一切都按預期工作。
更新:我剛剛被告知版本不匹配對db:migrate
無關緊要。 這對db:push
來說無疑是重要的,所以我不確定是什么問題。 在任何情況下,當我使用相同的Gemfile和1.9.2初始化一個新的應用程序時,它的工作原理。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.