加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails – Rails / ActiveRecord – AdapterNotSpecified

发布时间:2020-12-17 04:27:29 所属栏目:百科 来源:网络整理
导读:我正在做 Ruby on Rails Tutorial.在前三章中它使用SQLite,但后来它建议在开发中使用PostgreSQL以便更容易地进行Heroku部署.在编辑我的database.yml和Gemfile以使用pg而不是sqlite3之后,它似乎有效 – 除非使用Rake运行测试.它会弹出AdapterNotSpecified错误
我正在做 Ruby on Rails Tutorial.在前三章中它使用SQLite,但后来它建议在开发中使用PostgreSQL以便更容易地进行Heroku部署.在编辑我的database.yml和Gemfile以使用pg而不是sqlite3之后,它似乎有效 – 除非使用Rake运行测试.它会弹出AdapterNotSpecified错误.

C:/Ruby/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activerecord-4.0.0/lib/active_record/
connection_adapters / connection_specification.rb:52:in resolve_hash_connection’:
数据库配置未指定适配器(ActiveRecord :: AdapterNotSpecif
IED)

等等

database.yml指定了一个适配器,如下所示:

development:
  adapter: postgresql
  host: localhost
  username: nekkoru
  password: derpderp
  database: development
  encoding: UTF8

这是怎么回事?我使用的是Windows 7 x64,Ruby 1.9.3,Rails 4.0.0,PostgreSQL 9.3.0.1.

解决方法

您没有为测试环境定义数据库.您的database.yml文件应如下所示:
development:
  adapter: postgresql
  host: localhost
  username: nekkoru
  password: derpderp
  database: development
  encoding: UTF8

test:
  adapter: postgresql
  host: localhost
  username: nekkoru
  password: derpderp
  database: test        # or whatever the name is
  encoding: UTF8

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读