我是 Rails 的初学者,试图将我的小应用程序推送到 heroku。在本地,我已将我的数据库从 mysql2
移动到 postgresql
,但无法在 heroku 上运行我的应用程序。在本地一切都按预期运行。
production:
adapter: postgresql
database: database_production
pool: 5
timeout: 5000
运行 heroku run rake db:create
或 heroku run rake db:migrate
返回:
$ heroku run rake --trace db:create
Running `rake --trace db:create` attached to terminal... up, run.5709
** Invoke db:create (first_time)
** Invoke db:load_config (first_time)
** Execute db:load_config
** Execute db:create
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 run gem install pg
$ heroku run gem install pg
Running `gem install pg` attached to terminal... up, run.9322
Fetching: pg-0.18.1.gem (100%)
Building native extensions. This could take a while...
Successfully installed pg-0.18.1
invalid options: -f fivefish
(invalid options are ignored)
Parsing documentation for pg-0.18.1
Installing ri documentation for pg-0.18.1
Done installing documentation for pg after 3 seconds
1 gem installed
$ heroku run gem install pg
Running `gem install pg` attached to terminal... up, run.7925
Fetching: pg-0.18.1.gem (100%)
Building native extensions. This could take a while...
Successfully installed pg-0.18.1
invalid options: -f fivefish
(invalid options are ignored)
Parsing documentation for pg-0.18.1
Installing ri documentation for pg-0.18.1
Done installing documentation for pg after 4 seconds
1 gem installed
...
..etc
我也注意到了一些奇怪的事情,但不确定是否相关。运行 heroku run bundle install --no-deployment
显示正在安装 mysql2
,但我已经将其从 gemfile 中删除。
Running `bundle install --no-deployment` attached to terminal... up, run.1928
Fetching gem metadata from https://rubygems.org/.........
Installing i18n 0.7.0
Installing rake 10.4.2
Installing thread_safe 0.3.4
Installing minitest 5.5.1
Installing erubis 2.7.0
Installing builder 3.2.2
Installing mini_portile 0.6.2
Installing rack 1.6.0
Installing mime-types 2.4.3
Installing arel 6.0.0
Installing execjs 2.3.0
Installing sass 3.4.12
Installing json 1.8.2
Installing cancancan 1.10.1
Installing chunky_png 1.3.4
Installing coffee-script-source 1.9.1
Installing thor 0.19.1
Installing multi_json 1.10.1
Installing rb-fsevent 0.9.4
Installing hike 1.2.3
Installing tilt 1.4.1
Installing bcrypt 3.1.10
Using bundler 1.7.12
Installing tzinfo 1.2.2
Installing mysql2 0.3.18
Installing rack-test 0.6.3
Installing mail 2.6.3
Installing compass-import-once 1.0.5
Installing autoprefixer-rails 5.1.7
Installing rdoc 4.2.0
Installing uglifier 2.7.0
Installing coffee-script 2.3.0
Installing compass-core 1.0.3
Installing sprockets 2.12.3
Installing activesupport 4.2.0
Installing bootstrap-sass 3.3.3
Installing sdoc 0.4.1
Installing rails-deprecated_sanitizer 1.0.3
Installing globalid 0.3.3
Installing activemodel 4.2.0
Installing jbuilder 2.2.7
Installing activejob 4.2.0
Installing activerecord 4.2.0
Installing ffi 1.9.6
Installing rb-inotify 0.9.5
Installing compass 1.0.3
Installing compass-normalize 1.5
Installing nokogiri 1.6.6.2
Installing loofah 2.0.1
Installing rails-dom-testing 1.0.5
Installing rails-html-sanitizer 1.0.1
Installing actionview 4.2.0
Installing actionpack 4.2.0
Installing sprockets-rails 2.2.4
Installing railties 4.2.0
Installing coffee-rails 4.1.0
Installing sass-rails 5.0.1
Installing turbolinks 2.5.3
Installing jquery-rails 4.0.3
Installing compass-rails 2.0.4
Installing actionmailer 4.2.0
Installing rails 4.2.0
Your bundle is complete!
Gems in the groups development and test were not installed.
It was installed into ./vendor/bundle
最佳答案
您必须将 pg
添加到您的 Gemfile
并运行 bundle install
而不是尝试在 heroku 上手动安装该 gem。将此添加到应用程序的 Gemfile
:
gem 'pg'
关于ruby-on-rails - heroku run rake db :migrate fails, 未找到 gem pg; gem install pg 重复,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28656863/