在heroku上,rake db:migrate失败,并显示“数据库配置未指定适配器”。 [英] On heroku, rake db:migrate fails with "database configuration does not specify adapter"

查看:148
本文介绍了在heroku上,rake db:migrate失败,并显示“数据库配置未指定适配器”。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遵循 Rails教程直到链接点。



以下是shell输出:

  jrhorn424在〜/学习/ rails / rails-tutorial / demo_app上master 
$ heroku运行rake db:migrate
运行rake db:migrate attach to terminal ... up,run.2

###剪切###

迁移到CreateUsers(20120310145100)
迁移到CreateMicroposts(20120311052021)
rake中止!
数据库配置没有指定适配器

任务:TOP => db:schema:dump
(通过使用--trace运行任务来查看完整跟踪)

我已经咨询了 Heroku快速入门,并做了一些Google搜索。我怀疑问题出在 config / database.yml 之上,因为在我的开发环境中,它充满了对 sqlite3 的引用。但是,在服务器上,同一个文件包含以下几行:

  adapter = uri.scheme 
适配器=postgresqlif adapter ==postgres

通过已部署的应用程序添加数据会成功,但会运行 heroku run rake db:migrate 仍然失败。



这是我的Gemfile:

  source'https://rubygems.org'

gem'rails','3.2.2'

#Bundle Edge Rails改为:
#gem'rails',:git => 'git://github.com/rails/rails.git'

group:development do
gem'sqlite3','1.3.5'
end

#默认情况下,Gems仅用于资产,并且在生产环境中不需要
#。
group:assets do
gem'sass-rails','3.2.4'
gem'coffee-rails','3.2.2'

#参见https://github.com/sstephenson/execjs#readme获得更多支持的运行时
#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并且只包含

pre $

$ b $ c $ <$ pre

靠近您的Gemfile顶部。

执行a:

  bundle 
bundle exec rake db:create
bundle exec rake db:migrate

尝试再次提交并重新推送(您已知道如何执行此操作)。



让我知道如果这样做't work。



PS,这里是我的database.yml文件的样子:

 #PostgreSQL v0.8.x 
#gem install pg
开发:
适配器:postgresql
编码:unicode
主机:localhost
数据库:health_development
池:5
用户名:volpine
密码:密码

#警告:定义为test的数据库将被删除,$ b运行rake时从开发数据库重新生成$ b#。
#不要将此db设置为与开发或生产相同。
测试:
适配器:postgresql
编码:unicode
主机:localhost
数据库:health_test
池:5
用户名:volpine
密码:密码

产品:
适配器:postgresql
编码:unicode
主机:localhost
数据库:health_production
池:5
用户名:volpine
密码:密码


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

解决方案

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

这篇关于在heroku上,rake db:migrate失败,并显示“数据库配置未指定适配器”。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆