加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails – 由于缺少pg gem,Rails服务器无法启动.卸载post

发布时间:2020-12-17 01:56:48 所属栏目:百科 来源:网络整理
导读:我在尝试启动Rails 5服务器时收到错误. 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). 我通过brew删除了本地postgres,也
我在尝试启动Rails 5服务器时收到错误.

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

我通过brew删除了本地postgres,也删除了现有的mac app.
这是我的Gemfile

source 'https://rubygems.org'

gem 'rails','5.0.0'
gem 'puma','3.4.0'
gem 'sass-rails','5.0.6'
gem 'uglifier','3.0.0'
gem 'coffee-rails','4.2.1'
gem 'jquery-rails','4.1.1'
gem 'turbolinks','5.0.0'
gem 'jbuilder','2.4.1'

group :development,:test do
  gem 'sqlite3'
  gem 'byebug','9.0.0',platform: :mri
end

group :development do
  gem 'web-console','3.1.1'
  gem 'listen','3.0.8'
  gem 'spring','1.7.2'
  gem 'spring-watcher-listen','2.0.0'
end

group :production do
  gem 'pg'
end

# Windows does not include zoneinfo files,so bundle the tzinfo-data gem
gem 'tzinfo-data',platforms: [:mingw,:mswin,:x64_mingw,:jruby]

我用了

bundle install –without production

但我仍然得到同样的错误.有人可以帮忙吗?

谢谢,

解决方法

在我看来,您使用rails命令设置应用程序并传递选项以使用postgres数据库.这将自动存根您的database.yml文件,并为postgres配置它.说实话,我建议你设置一个数据库,就像你在prod中所期望的那样.它不是那么重,会让你头疼. (像这样!)

虽然我不认为这是最好的推理,但就个人而言,您可能会尝试像这样配置您的rails应用:

在你的Gemfile中:

group :development,:test do
  # Use sqlite3 as the database for Active Record
  gem 'sqlite3'
end

group :production do
  # Use postgresql as the database for Active Record
  gem 'pg','~> 0.18'
end

然后在你的config / database.yml中:

postgres: &postgres
  adapter: postgresql
  encoding: unicode
  pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>

sqlite: &sqlite
  adapter: sqlite3
  pool: 5
  timeout: 5000

development:
  <<: *sqlite
  database: db/development.sqlite3

test:
  <<: *sqlite
  database: db/test.sqlite3

production:
  <<: *postgres
  database: postgresapp_production
  username: postgresapp
  password: <%= ENV['POSTGRESAPP_DATABASE_PASSWORD'] %>

这应该对你有用.

为了解释,我所做的一切基本上都是从sqlite rails应用程序中获取存根配置,并将database.yml文件中的默认,开发和测试配置部分粘贴到postgres rails应用程序的database.yml上,并在开发之上.测试部分.然后我将sqlite配置中的所有“默认”更改为“sqlite”,将postgres部分中的所有“默认”更改为“postgres”.然后我将sqlite gem添加到Gemile中的开发/测试环境中,并将pg gem仅移动到生产中.

您必须先运行bundle命令和db:create任务,然后才能运行它.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读