Heroku with rails 5 error Gem :: LoadError:为数据库适配器指定'postgresql'

编程入门 行业动态 更新时间:2024-10-24 14:25:43
本文介绍了Heroku with rails 5 error Gem :: LoadError:为数据库适配器指定'postgresql'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

之前我用过SQLite3,后来当我明白我需要postgresql时,我安装了同样的并在本地机器上工作。

从sqlite迁移到postgresql后,一次部署进展顺利。现在我看到一些问题。

Heroku日志,Gem文件和Database.yml详细信息如下。

可以有人帮助我这个请。

预先感谢... !!!

部分宝石file:

group:development,:test do gem'pg','〜> 1.0.0' gem'rails_12factor' #gem'sqlite3'#在代码的任何地方调用'byebug'来停止执行并获得一个调试器控制台 gem'byebug' ,平台:[:mri,:mingw,:x64_mingw] #增加对水豚系统测试和硒驱动程序的支持 gem'capybara','〜> 2.13' gem'selenium-webdriver' end group:production do gem'pg','〜> 1.0.0' gem'rails_12factor' end group:development do #访问异常页面上的IRB控制台或使用<%= console% >代码中的任何地方。 gem'web-console','> = 3.3.0' end #Windows不包含zoneinfo文件,所以将tzinfo-data gem gem'tzinfo-data',平台:[:mingw,:mswin,:x64_mingw,:jruby]

Database.yml:

开发:适配器:postgresql 编码:unicode database:database_postgresql pool:5 用户名:postgres 密码:secret 测试:适配器:postgresql 编码:unicode database:database_postgresql_test pool:5 用户名:postgres 密码:secret $ b生产:适配器:postgresql 编码:unicode database:database_postgresql pool:5 username:postgres 密码:secret

部分Heroku日志。

remote:----->安装node-v6.11.1-linux-x64 remote:----->检测rake任务 remote:----->为Rails资产管道准备应用程序 remote:正在运行:rake资产:预编译 remote:在系统中未检测到Yarn可执行文件。 remote:通过yarnpkg/en/docs/install下载纱线 remote:I,[2018-01-15T13:38:08.180450#590]信息 - :写入/ tmp /build_3dd0bceef080f0d8f6be5bc51b9d4a48/public/assets/jumbotron--032aba6cd1415006731040523573e7138c703aedc6d1f46b3622cbe4c9feec27.jpg remote:rake aborted! remote:Gem :: LoadError:为数据库适配器指定'postgresql',但未加载该gem。将`gem'pg'`添加到您的Gemfile中(并确保其版本处于ActiveRecord所要求的最低限度)。 remote:/tmp/build_3dd0bceef080f0d8f6be5bc51b9d4a48/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/connection_adapters/connection_specification.rb:188:in`rescue in spec' remote:/tmp/build_3dd0bceef080f0d8f6be5bc51b9d4a48/vendor/bundle/ruby/2.3.0/gems/sprockets-rails-3.2.1/lib/sprockets/rails/task.rb:67:in`block(2 levels )in define' remote:/tmp/build_3dd0bceef080f0d8f6be5bc51b9d4a48/vendor/bundle/ruby/2.3.0/gems/rake-12.3.0/exe/rake:27:in`< top(required)>' remote:任务:TOP =>资产:预编译 remote:(通过使用--trace运行任务查看完整跟踪) remote:! remote:!预编译资产失败。 remote:! remote:!推送被拒绝,未能编译Ruby应用程序。 remote: remote:!推送失败 remote:验证部署... remote: remote:!拒绝拒绝超过28813。

解决方案

如果您最近将应用程序部署到Heroku,并且当您进入Heroku应用程序链接时,您的尝试一直在收到应用程序崩溃错误,但是其他所有内容似乎都是按顺序排列的,这很可能是由于新版本的'pg'gem 。 Postgres发布了一个新版本的gem,它似乎还不完全兼容,所以在 group production 下的Gemfile中更改行:

gem'pg'或 gem'pg','〜> 1.0.0'

gem'pg','〜> 0.11'或 gem'pg','〜> 0.20.0'

注意: 在> 之前使用波浪符号,那不是破折号

在您的小组制作中进行此更新后, Gemfile,确保你运行 bundle install --without production (更新Gemfile.lock文件),做一个git add / commit循环,然后重新部署到Heroku。 p>

良好实践

使用 pg gem 一次没有:group ,因为你的数据库对于开发& 生产!

I am a Rails beginner and i see some issue while deploying to Heroku.

Earlier i used SQLite3, later when i understood that i needed postgresql i installed the same and work on local machine.

One deployment went fine after migrating from sqlite to postgresql. Now i see some issue.

Heroku logs, Gem file and Database.yml details are as below.

Can some one help me in this please.

Advance Thanks...!!!

Part of Gem file:

group :development, :test do gem 'pg', '~> 1.0.0' gem 'rails_12factor' #gem 'sqlite3' # Call 'byebug' anywhere in the code to stop execution and get a debugger console gem 'byebug', platforms: [:mri, :mingw, :x64_mingw] # Adds support for Capybara system testing and selenium driver gem 'capybara', '~> 2.13' gem 'selenium-webdriver' end group :production do gem 'pg', '~> 1.0.0' gem 'rails_12factor' end group :development do # Access an IRB console on exception pages or by using <%= console %> anywhere in the code. gem 'web-console', '>= 3.3.0' end # Windows does not include zoneinfo files, so bundle the tzinfo-data gem gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]

Database.yml:

development: adapter: postgresql encoding: unicode database: database_postgresql pool: 5 username: postgres password: secret test: adapter: postgresql encoding: unicode database: database_postgresql_test pool: 5 username: postgres password: secret production: adapter: postgresql encoding: unicode database: database_postgresql pool: 5 username: postgres password: secret

Part of Heroku logs.

remote: -----> Installing node-v6.11.1-linux-x64 remote: -----> Detecting rake tasks remote: -----> Preparing app for Rails asset pipeline remote: Running: rake assets:precompile remote: Yarn executable was not detected in the system. remote: Download Yarn at yarnpkg/en/docs/install remote: I, [2018-01-15T13:38:08.180450 #590] INFO -- : Writing /tmp/build_3dd0bceef080f0d8f6be5bc51b9d4a48/public/assets/jumbotron--032aba6cd1415006731040523573e7138c703aedc6d1f46b3622cbe4c9feec27.jpg remote: rake aborted! remote: Gem::LoadError: 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). remote: /tmp/build_3dd0bceef080f0d8f6be5bc51b9d4a48/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/connection_adapters/connection_specification.rb:188:in `rescue in spec' remote: /tmp/build_3dd0bceef080f0d8f6be5bc51b9d4a48/vendor/bundle/ruby/2.3.0/gems/sprockets-rails-3.2.1/lib/sprockets/rails/task.rb:67:in `block (2 levels) in define' remote: /tmp/build_3dd0bceef080f0d8f6be5bc51b9d4a48/vendor/bundle/ruby/2.3.0/gems/rake-12.3.0/exe/rake:27:in `<top (required)>' remote: Tasks: TOP => assets:precompile remote: (See full trace by running task with --trace) remote: ! remote: ! Precompiling assets failed. remote: ! remote: ! Push rejected, failed to compile Ruby app. remote: remote: ! Push failed remote: Verifying deploy... remote: remote: ! Push rejected to damp-beyond-28813.

解决方案

If you have recently deployed your app to Heroku and in your attempt have been getting the "App crashed" error when you go to the Heroku app link, but everything else seems to be in order, it's most likely due to a new release of the 'pg' gem. Postgres has released a new version of its gem which seems not fully compatible yet, so in your Gemfile under group production change the line:

gem 'pg' OR gem 'pg', '~> 1.0.0'

to

gem 'pg', '~> 0.11' OR gem 'pg', '~> 0.20.0'

Note: the tilde sign before the >, that's not a dash

Once you make this update in your group production of your Gemfile, ensure you run bundle install --without production (to update Gemfile.lock file), do a git add/commit cycle, then re-deploy to Heroku.

For Good Practice

Use pg gem one time without :group because your database is same for both development & production!

更多推荐

Heroku with rails 5 error Gem :: LoadError:为数据库适配器指定'postgresql'

本文发布于:2023-10-16 10:29:29,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:适配器   数据库   error   rails   Heroku

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!