2015-10-05 44 views
1

localhost:3000是给我这个错误:本地主机:3000个索赔“宝石‘PG’”在没有安装,Heroku的应用程序工作正常

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).

创业板安装并已捆绑在一起。令我困惑的是Heroku应用程序工作正常。我尝试运行rake db:create时也遇到同样的错误。

我目前正在注册一个学习RoR的课程,我在社区论坛上提过这个问题,但没有运气。

我的Gemfile是:

source 'https://rubygems.org' 
ruby '2.2.1' 


gem 'rails', '4.2.4' 

gem 'sass-rails', '~> 5.0' 

gem 'bootstrap-sass', '~> 3.3.5' 

gem 'uglifier', '>= 1.3.0' 

gem 'coffee-rails', '~> 4.1.0' 

gem 'turbolinks' 

gem 'jbuilder', '~> 2.0' 

gem 'sdoc', '~> 0.4.0', group: :doc 

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

group :production do 

gem 'pg', '~>0.18.3' 

gem 'rails_12factor' 

end 

group :development, :test do 

    gem 'byebug' 

end 

group :development do 

    gem 'spring' 

end 

我的database.yml是:

default: &default 
    adapter: postgresql 
    pool: 5 
    timeout: 5000 

development: 

    <<: *default 
    adapter: postgresql 
    encoding: unicode 
    database: my_development 
    username: davideye 
    password: 1234 
    host: localhost 
    port: 5432 


test: 

    <<: *default 
    database: my_test 
    username: davideye 
    password: 1234 

production: 

    <<: *default 
    database: my_production 
    username: davideye 
    password: 1234 
+0

显示您的gemfile。我认为这是你把PG宝石放在哪里的问题。您需要在'production'环境中添加'pg',以及您在'development'中使用的任何其他设备env – nik

+0

gem pg正在生产中,并且sqlite3正在开发中。 Stackflow不会让我发布截图,因为我是一个新用户 – Eyelabs

+0

只需将'gemfile'作为代码复制粘贴到您的问题中即可。你不需要屏幕截图。 – nik

回答

1

在database.yml中已为发展地方在Gemfile中已为发展定义sqlite3定义postgres。所以要么改变你的database.yml或在开发中的gemfile而不是sqlite3pg

0

当您使用sqlite3两个devtest ENV

# Gemfile 
group :development, :test do 
    gem 'sqlite3' 
end 

更改适配器sqlite3在您的开发和试块为好。

# config/database.yml 
default: &default 
    pool: 5 
    timeout: 5000 

development: 
    <<: *default 
    adapter: sqlite3 
    database: db/my_development.sqlite3 

test: 
    <<: *default 
    adapter: sqlite3 
    database: db/my_test.sqlite3 

production: 
    <<: *default 
    adapter: postgresql 
    database: my_production 
    username: davideye 
    password: 1234 
    host: localhost 
    port: 5432 
1

这里的问题是你的Gemfile。

group :production do 
     gem 'pg', '~>0.18.3' 
     gem 'rails_12factor' 
    end 

这告诉捆扎机只加载pg生产(这就是为什么它的工作原理在Heroku)。

您可以将gem 'pg' ...移出group :production块,以便它也包含在开发中,或者在开发环境中使用sqlite3。

0

的问题是,因为你在生产模式&添加宝石“PG”的开发使用的是“源码”按你的Gemfile,但你根据你使用的database.yml发展PostgreSQL的

所以,删除从生产块&的宝石'pg'放在任何块之前。