Ruby on rails PostgreSQL未安装在Ruby on Rails上

Ruby on rails PostgreSQL未安装在Ruby on Rails上,ruby-on-rails,postgresql,Ruby On Rails,Postgresql,我试图在我的Ruby应用程序上安装PostgreSQL,但遇到了一个问题。每当我尝试启动服务器时,都会出现一个错误,说明: rescue in spec”:为数据库适配器指定了“postgresql”,但未加载gem。将gem“pg”添加到您的gem文件中(并确保其版本为ActiveRecord要求的最低版本)。 这很奇怪,因为我已经将它添加到我的Gemfile中,并运行了bundle install和bundle list,以检查它是否已安装(即已安装) 让你明白我做了什么 我已经启动了我的P

我试图在我的Ruby应用程序上安装PostgreSQL,但遇到了一个问题。每当我尝试启动服务器时,都会出现一个错误,说明:

rescue in spec”:为数据库适配器指定了“postgresql”,但未加载gem。将gem“pg”添加到您的gem文件中(并确保其版本为ActiveRecord要求的最低版本)。

这很奇怪,因为我已经将它添加到我的Gemfile中,并运行了
bundle install
bundle list
,以检查它是否已安装(即已安装)

让你明白我做了什么

我已经启动了我的PostgreSQL数据库,创建了一个数据库,并给了它一个名称和密码

然后我将数据库.yml更改为:

# SQLite version 3.x
#   gem install sqlite3
#
#   Ensure the SQLite 3 gem is defined in your Gemfile
#   gem 'sqlite3'
#
default: &default
  adapter: postgresql
  encoding: unicode
  pool: 5

  # Important configs for cloud9, change password value
  # to what you entered in the previous psql step.
  template: template0 (not sure what the fill in here?)
  username: my_username (can be omitted)
  password: my_password (can be omitted)

development:
  <<: *default
  database: my_database_development

test:
  <<: *default
  database: my_database_test

production:
  <<: *default
  database: my_database_production
  username: my_username
  password: <%= ENV['my_password'] %>
然后,我尝试启动服务器并出现以下错误:

=> Booting WEBrick
=> Rails 4.2.6 application starting in development on http://0.0.0.0:8080
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
Exiting
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.6/lib/active_record/connection_adapters/connection_specification.rb:177:in `rescue in spec': Specified 'postgresql' for database adapter, but the gem is not loaded. Add `gem 'pg'` to your Gemfile (and ensure its version is at the minimum required by ActiveRecord). (Gem::LoadError)
编辑(CET时间18-01-31晚上10:12)


我在Cloud9(ubuntu)上运行这个应用程序,以前/现在的数据库是SQlite(默认),但现在我想部署这个网站,它需要改成更好的数据库。因此,PostgreSQL,当前pg版本为1.0,请尝试删除此版本:

group :production do
  gem 'pg'
end

pg
gem已经在外部范围中定义了,因此它不需要在
production
组中定义。另外,请使用
bundle exec rails s启动服务器
以在当前
Gemfile
的上下文中运行rails服务器。请尝试删除此文件:

group :production do
  gem 'pg'
end

pg
gem已经在外部范围中定义了,因此它不需要在
production
组中定义。另外,请使用
bundle exec rails启动服务器,以便在
Gemfile
的当前上下文中运行rails服务器,只需将
gem'pg'
的第一次出现保留在Gemfile的顶部即可。所有其他人都应该离开

然后,如前所述,使用bundle exec rails启动应用程序


然后应该工作。

只需将第一次出现的
gem'pg'
保留在gem文件的顶部即可。所有其他人都应该离开

然后,如前所述,使用bundle exec rails启动应用程序


然后应该可以工作。

我想,这是一个
pg
与当前rails版本的兼容性问题。这里有许多线程提到rails与pg 1.0的不兼容性。将pg gem降级到以前最稳定的版本
0.21
应该适合您。试试看

gem 'pg', '~> 0.21'

希望这对您有所帮助,我想,这是您当前rails版本的兼容性问题。这里有许多线程提到rails与pg 1.0的不兼容性。将pg gem降级到以前最稳定的版本
0.21
应该适合您。试试看

gem 'pg', '~> 0.21'


希望这有助于

运行
bundle show pg
,你看到gem列表了吗?你能尝试将
gem'pg',“~>0.21'
添加到gemfile和bundle中吗?@imechemi它在1.0.0I上,我会试试,为什么是0.21tho?@anesmuhammed我降级了pg,效果很好。你能写下这个作为答案,这样我们就可以结束这个问题吗?运行
bundle show pg
,你看到列出的gem了吗?你能尝试将
gem'pg',“~>0.21'
添加到gemfile和bundle中吗?@imechmi它在1.0.0上,我会试试,为什么是0.21 tho?@AneesMuhammed我降级了pg,它起了作用。你能写下这个作为答案,这样我们就可以结束这个问题了吗?只是为了补充一下-相同的代码复制了Gemfile的开发和开发/测试组中的
pg
gem…只是为了补充一下-相同的代码复制了Gemfile的开发和开发/测试组中的
pg
gem…仍然存在说gem没有加载:(你能提供一些背景信息吗:哪个操作系统,哪个数据库版本,当前Gemfile的pg gem版本和当前数据库yaml。只需更新你的问题。你是否运行bundle install来安装所有必需的gem?是的,我现在就更新这个问题。当前的yaml和Gemfile已经发布在问题中了:)仍然说gem没有加载:(你能提供一些背景信息吗:哪个操作系统,哪个数据库版本,当前的Gemfile和pg gem版本以及当前的数据库yaml。只需更新你的问题。你是否运行bundle install来安装所有必需的gem?是的,我现在就更新这个问题。当前的yaml和Gemfile已经发布在问题中了:)谢谢你的回答,它确实帮助了我!:)谢谢你的回答,它确实帮助了我!:)