Ruby on rails 赫罗库·元';不认识';pg';我的Rails应用程序Gemfile中的gem
我对RubyonRails还是一个相对的新手,对Heroku也是一个完全的新手 我已经将Rails应用程序设置为在开发和生产过程中使用postgres而不是sqlite3,并且在Gemfile中添加了“gem'pg'”。在本地,我的应用程序运行良好 让它在Heroku上运行是另一回事。在我将我的应用程序推送到Heroku之后,当我键入“Heroku run rake db:migrate”时,它告诉我,“rake中止!为数据库适配器指定了'postgresql',但gem未加载。将Ruby on rails 赫罗库·元';不认识';pg';我的Rails应用程序Gemfile中的gem,ruby-on-rails,postgresql,heroku,Ruby On Rails,Postgresql,Heroku,我对RubyonRails还是一个相对的新手,对Heroku也是一个完全的新手 我已经将Rails应用程序设置为在开发和生产过程中使用postgres而不是sqlite3,并且在Gemfile中添加了“gem'pg'”。在本地,我的应用程序运行良好 让它在Heroku上运行是另一回事。在我将我的应用程序推送到Heroku之后,当我键入“Heroku run rake db:migrate”时,它告诉我,“rake中止!为数据库适配器指定了'postgresql',但gem未加载。将gem'pg'
gem'pg'
添加到您的gem文件中。”
是的,gem'pg'
在我的gem文件中,但我仍然收到这个错误
有什么好处
下面是我的Gemfile现在的样子:
source 'https://rubygems.org'
ruby '2.0.0'
gem 'rails', '4.0.1'
gem 'pg'
group :assets do
end
gem 'bcrypt-ruby', '~> 3.1.2'
gem 'haml'
gem 'devise', '3.0.0.rc'
gem 'protected_attributes'
gem 'sass-rails', '4.0.1'
gem 'uglifier', '2.1.1'
gem 'coffee-rails', '4.0.1'
gem 'jquery-rails', '3.0.4'
gem 'turbolinks', '1.1.1'
gem 'jbuilder', '1.0.2'
gem 'knockout-rails'
# To use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.0.0'
# To use Jbuilder templates for JSON
# gem 'jbuilder'
# Use unicorn as the app server
# gem 'unicorn'
# Deploy with Capistrano
# gem 'capistrano'
# To use debugger
# gem 'debugger'
group :doc do
gem 'sdoc', '0.3.20', require: false
end
group :production do
gem 'unicorn'
gem 'rails_12factor', '0.0.2'
end
我的database.yml是这样的:
development:
adapter: postgresql
encoding: unicode
database: financemeter
pool: 5
password:
test:
adapter: postgresql
encoding: unicode
database: financemeter
pool: 5
timeout: 5000
production:
adapter: postgresql
database: dbe67fgdnnqg88
pool: 5
timeout: 5000
user: njatxlpjjrzfoe
password: HULxOtPALAk4FnzZe-_737TvPc
下面是我尝试在heroku上迁移时的完整错误日志。(同样,在本地我很好。如果有必要的话,我正在本地使用MacBook。)
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.1/lib/active\u record/connection\u adapters/connection\u specification.rb:58:in“rescue in resolve\u hash\u connection”
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.1/lib/active\u record/connection\u adapters/connection\u specification.rb:55:in'resolve\u hash\u connection'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.1/lib/active\u record/connection\u adapters/connection\u specification.rb:46:in`resolve\u string\u connection'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.1/lib/active\u record/connection\u adapters/connection\u specification.rb:32:in'spec'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.1/lib/active\u record/connection\u handling.rb:39:在“建立连接”中
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.1/lib/active_-record/railtie.rb:176:in“block(2层)in”
/app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.1/lib/active\u support/lazy\u load\u hooks.rb:38:in'instance\u eval'
/app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.1/lib/active\u support/lazy\u load\u hook.rb:38:in'execute\u hook'
/app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.1/lib/active\u-support/lazy\u-load\u-hooks.rb:28:in'block-in-on\u-load'
/app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.1/lib/active\u support/lazy\u load\u hooks.rb:27:in'each'
/app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.1/lib/active\u support/lazy\u load\u hooks.rb:27:in'on\u load'
/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.1/lib/active\u record/railtie.rb:174:in'block in'
/app/vendor/bundle/ruby/2.0.0/gems/railties-4.0.1/lib/rails/initializable.rb:30:in'instance_exec'
/app/vendor/bundle/ruby/2.0.0/gems/railties-4.0.1/lib/rails/initializable.rb:30:in'run'
/app/vendor/bundle/ruby/2.0.0/gems/railties-4.0.1/lib/rails/initializable.rb:55:在“运行中的块初始化器”中
/app/vendor/bundle/ruby/2.0.0/gems/railties-4.0.1/lib/rails/initializable.rb:54:in'run_initializers'
/app/vendor/bundle/ruby/2.0.0/gems/railties-4.0.1/lib/rails/application.rb:215:in'initialize!'
/app/vendor/bundle/ruby/2.0.0/gems/railties-4.0.1/lib/rails/railtie/configurable.rb:30:in'method_missing'
/app/config/environment.rb:5:in`'
/app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.1/lib/active\u support/dependencies.rb:229:in'require'
/app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.1/lib/active\u support/dependencies.rb:229:in'block in require'
/app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.1/lib/active\u support/dependencies.rb:214:in'load\u dependencity'
/app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.1/lib/active\u support/dependencies.rb:229:in'require'
/app/vendor/bundle/ruby/2.0.0/gems/railties-4.0.1/lib/rails/application.rb:189:在“require_环境”中
/app/vendor/bundle/ruby/2.0.0/gems/railties-4.0.1/lib/rails/application.rb:250:在“运行任务中的块”中
您的计算机上是否安装了postgresql如果没有,请使用自制软件安装第页。
安装后,确保初始化pg数据存储。
此外,根据pg的安装方式,可能需要在database.yml文件中指定用户名和主机
username: someuser_on_pg
host: localhost
希望这有助于确保进行捆绑安装,并在安装后提交Gemfile和Gemfile.lock。试着部署,我试过了,没用。我真的想知道这是否是因为Heroku没有得到更新——当我执行“git push Heroku master”时,它会返回一条简单的“Everything-up-date”消息,而不告诉我我的更改已被推送。你知道你的gem文件中有两次“pg”gem吗?尝试将其从
:production
组中删除,然后运行bundle update
,bundle install
并尝试推送。哎呀,感谢您指出这一点。我从制作组中取出了这一行,并修改了我的帖子以反映这一点。不幸的是,它不起作用,我仍然有这个问题(你在使用git分支吗?也许你把git搞砸了。试着git push-f heroku master
强制推到远程头部。@drumwolf你在heroku仪表板帐户或命令行上添加了heroku Postgres服务器的实例了吗?heroku插件:添加heroku PostgreSql我想我可能已经添加了。我最终还是创建了heroku PostgreSql使用“-database=postgresql”命令从头开始创建一个全新的Rails应用程序,然后将我的所有资产、控制器、模型、视图等从我的旧应用程序迁移到新应用程序,最后将它们合并到github中。非常不雅观,但效果不错。
username: someuser_on_pg
host: localhost