在heroku上,rake db:migrate失败,“数据库配置未指定适配器”
我已经按照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
我建议删除您的数据库:
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控制台时遇到了这个错误,
当我给,
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
我碰到了这个,发现手动设置RAILS_ENV对我来说很有用:
heroku run RAILS_ENV=production rake db:migrate
当我运行heroku db:push
,我得到了一个水龙头错误 ,导致我切换到使用ruby 1.9.2。 切换版本并启动新应用程序后,我不再收到来自heroku run rake db:migrate
的错误,一切都按预期工作。
更新:我刚刚被告知版本不匹配对db:migrate
无关紧要。 这对db:push
来说无疑是重要的,所以我不确定是什么问题。 无论如何,当我使用相同的Gemfile和1.9.2初始化一个新应用程序时,它可以工作。
我有同样的问题。 它发生了,因为我从我的heroku应用程序中删除了RAILS_ENV环境变量,只留下了一个RACK_ENV环境变量。
添加RAILS_ENV =生产确实解决了这个问题:
heroku config:add RAILS_ENV=production --app XXXX-production
Heroku不查看你的database.yml文件,它查看DATABASE_URL – 如果没有设置,或者里面有拼写错误,那么你就会得到那个错误。
- 为什么Rake任务增强在我的本地环境和部署到Heroku Cedar之间有所不同?
- 你如何访问你的heroku数据库(特别是postgres)?
- Heroku – 如何写入“tmp”目录?
- 如何在Heroku上使用postgres扩展? 以及如何处理他们的迁移?
- 对于Ruby on Rails Heroku应用程序,如何将相关用户信息(不是全部)从一个生产数据库复制到另一个生产数据库
- 在部署到Heroku时,为什么Travis无法连接使用Redis cache_store?
- Heroku运行rake db:迁移错误,“没有这样的文件加载 – bundler / setup”
- 密钥就在那里,但我仍然得到`fetch’:找不到密钥:“S3_BUCKET_NAME”(KeyError)
- DB上的错误:迁移“未初始化的常量DeviseCreateUsers”