簡體   English   中英

PostgreSQL不在Ruby on Rails上安裝

[英]PostgreSQL not installing on Ruby on Rails

我正在嘗試在Ruby應用程序上安裝PostgreSQL,但遇到了問題。 每當我嘗試啟動服務器時,都會出現錯誤消息:

rescue in spec': 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).

這很奇怪,因為我已經將其添加到我的Gemfile中,並運行bundle install和運行bundle list以檢查其是否已安裝(正確)。

引導您完成我的工作。

我已經啟動了PostgreSQL數據庫,創建了一個數據庫,並為其指定了名稱和密碼。

然后,我將database.yml更改為:

# SQLite version 3.x
#   gem install sqlite3
#
#   Ensure the SQLite 3 gem is defined in your Gemfile
#   gem 'sqlite3'
#
default: &default
  adapter: postgresql
  encoding: unicode
  pool: 5

  # Important configs for cloud9, change password value
  # to what you entered in the previous psql step.
  template: template0 (not sure what the fill in here?)
  username: my_username (can be omitted)
  password: my_password (can be omitted)

development:
  <<: *default
  database: my_database_development

test:
  <<: *default
  database: my_database_test

production:
  <<: *default
  database: my_database_production
  username: my_username
  password: <%= ENV['my_password'] %>

然后我將gem'pg gem 'pg'添加到我的gemfile中

source 'https://rubygems.org'


# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.2.6'
# Use sqlite3 as the database for Active Record
# gem 'sqlite3'
gem 'pg'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.1.0'
# See https://github.com/rails/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby

# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.0'
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.0', group: :doc

gem 'rake'
gem 'rspec'
gem 'kramdown'
gem 'thor', '0.19.1'
gem 'spree_braintree_vzero', github: 'spree-contrib/spree_braintree_vzero'
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'

# Use Unicorn as the app server
# gem 'unicorn'

# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development

group :development, :test do
  # Call 'byebug' anywhere in the code to stop execution and get a debugger console
  gem 'byebug'
  gem 'capistrano-passenger'
  gem 'capistrano-rails'
  gem 'capistrano-rvm'
  gem 'pg'
end

group :development do
  gem 'pg'
  # Access an IRB console on exception pages or by using <%= console %> in views
  gem 'web-console', '~> 2.0'

  # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
  gem 'spring'
end

gem 'spree', '~> 3.1.0.rc1'
gem 'spree_auth_devise', '~> 3.1.0.rc1'
gem 'spree_gateway', '~> 3.1.0.rc1'
gem 'devise'
gem 'materialize-sass'
gem 'active_link_to'
gem 'mollie-api-ruby'
# gem 'spree_mollie', github: 'salman15/mollie_spree_2017', branch: 'stable'
gem 'spree_mollie', github: 'ttcremers/spree_mollie', branch: 'stable'

group :production do
  gem 'pg'
end

然后,我嘗試啟動服務器並得到以下錯誤:

=> Booting WEBrick
=> Rails 4.2.6 application starting in development on http://0.0.0.0:8080
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
Exiting
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.6/lib/active_record/connection_adapters/connection_specification.rb:177:in `rescue in spec': 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). (Gem::LoadError)

編輯(歐洲中部時間31-01-18 10:12 pm)

我正在Cloud9(這是ubuntu)上運行該應用程序,以前/當前的數據庫是SQlite(默認),但是現在我要部署該網站,需要將其更改為更好的數據庫。 因此,PostgreSQL,當前的pg版本是1.0

請嘗試刪除此一個:

group :production do
  gem 'pg'
end

pg gem已在外部范圍中定義,因此不需要在production組中進行定義。 另外,請使用bundle exec rails s啟動服務器以在Gemfile當前上下文中運行rails服務器。

只需將gem 'pg'的首次出現保留在Gemfile的頂部即可。 所有其他人都應該離開。

然后,按照前面所述,使用bundle exec rails s啟動您的應用程序。

然后應該工作。

我想,這是您當前的Rails版本的pg兼容性問題。 這里有許多線程開放,提到了與pg 1.0的rails不兼容。 將pg gem降級到以前最穩定的版本0.21應該適合您。 你試一試

gem 'pg', '~> 0.21'

希望這可以幫助

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM