【问题标题】:Error while implementing postgresql on ruby on rails在 ruby​​ on rails 上实现 postgresql 时出错
【发布时间】:2013-02-12 04:20:31
【问题描述】:

在实现 rake db:migrate 时出现以下错误

rake aborted!
Please install the postgresql adapter: `gem install activerecord-postgresql-adapter` (pg is not part of the bundle. Add it to Gemfile.)

我使用 postgresql 在数据库中创建了两个表。

我的 database.yml 是

development:
  adapter: postgresql
  encoding: unicode
  host: localhost
  database: shop_development
  pool: 5
  username: postgres
  password: 

test:
  adapter: postgresql
  encoding: unicode
  host: localhost
  database: shop_test
  pool: 5
  username: postgres
  password: 

production:
  adapter: postgresql
  encoding: unicode
  host: localhost
  database: shop_production
  pool: 5
  username: postgres
  password: 

我也运行过如下命令:

C:\Sites\shop>gem install 'pg'
Successfully installed pg-0.14.1-x86-mingw32
1 gem installed
Installing ri documentation for pg-0.14.1-x86-mingw32...
Installing RDoc documentation for pg-0.14.1-x86-mingw32...

但这仍然给我同样的错误。

我的 gemfile 有以下内容:

GEM
  remote: https://rubygems.org/
  specs:
    actionmailer (3.2.11)
      actionpack (= 3.2.11)
      mail (~> 2.4.4)
    actionpack (3.2.11)
      activemodel (= 3.2.11)
      activesupport (= 3.2.11)
      builder (~> 3.0.0)
      erubis (~> 2.7.0)
      journey (~> 1.0.4)
      rack (~> 1.4.0)
      rack-cache (~> 1.2)
      rack-test (~> 0.6.1)
      sprockets (~> 2.2.1)
    activemodel (3.2.11)
      activesupport (= 3.2.11)
      builder (~> 3.0.0)
    activerecord (3.2.11)
      activemodel (= 3.2.11)
      activesupport (= 3.2.11)
      arel (~> 3.0.2)
      tzinfo (~> 0.3.29)
    activeresource (3.2.11)
      activemodel (= 3.2.11)
      activesupport (= 3.2.11)
    activesupport (3.2.11)
      i18n (~> 0.6)
      multi_json (~> 1.0)
    arel (3.0.2)
    builder (3.0.4)
    coffee-rails (3.2.2)
      coffee-script (>= 2.2.0)
      railties (~> 3.2.0)
    coffee-script (2.2.0)
      coffee-script-source
      execjs
    coffee-script-source (1.4.0)
    erubis (2.7.0)
    execjs (1.4.0)
      multi_json (~> 1.0)
    hike (1.2.1)
    i18n (0.6.1)
    journey (1.0.4)
    jquery-rails (2.2.1)
      railties (>= 3.0, < 5.0)
      thor (>= 0.14, < 2.0)
    json (1.7.6)
    mail (2.4.4)
      i18n (>= 0.4.0)
      mime-types (~> 1.16)
      treetop (~> 1.4.8)
    mime-types (1.21)
    multi_json (1.5.0)
    polyglot (0.3.3)
    rack (1.4.5)
    rack-cache (1.2)
      rack (>= 0.4)
    rack-ssl (1.3.3)
      rack
    rack-test (0.6.2)
      rack (>= 1.0)
    rails (3.2.11)
      actionmailer (= 3.2.11)
      actionpack (= 3.2.11)
      activerecord (= 3.2.11)
      activeresource (= 3.2.11)
      activesupport (= 3.2.11)
      bundler (~> 1.0)
      railties (= 3.2.11)
    railties (3.2.11)
      actionpack (= 3.2.11)
      activesupport (= 3.2.11)
      rack-ssl (~> 1.3.2)
      rake (>= 0.8.7)
      rdoc (~> 3.4)
      thor (>= 0.14.6, < 2.0)
    rake (10.0.3)
    rdoc (3.12.1)
      json (~> 1.4)
    sass (3.2.5)
    sass-rails (3.2.6)
      railties (~> 3.2.0)
      sass (>= 3.1.10)
      tilt (~> 1.3)
    sprockets (2.2.2)
      hike (~> 1.2)
      multi_json (~> 1.0)
      rack (~> 1.0)
      tilt (~> 1.1, != 1.3.0)
    sqlite3 (1.3.7-x86-mingw32)
    thor (0.17.0)
    tilt (1.3.3)
    treetop (1.4.12)
      polyglot
      polyglot (>= 0.3.1)
    tzinfo (0.3.35)
    uglifier (1.3.0)
      execjs (>= 0.3.0)
      multi_json (~> 1.0, >= 1.0.2)

PLATFORMS
  x86-mingw32

DEPENDENCIES
  coffee-rails (~> 3.2.1)
  jquery-rails
  rails (= 3.2.11)
  sass-rails (~> 3.2.3)
  sqlite3
  uglifier (>= 1.0.3)

我的 gemfile 有以下内容:-

source 'https://rubygems.org'

gem 'rails', '3.2.11'

# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'

# gem 'sqlite3'

 gem 'pg'


# Gems used only for assets and not required
# in production environments by default.
group :assets do
  gem 'sass-rails',   '~> 3.2.3'
  gem 'coffee-rails', '~> 3.2.1'

  # See https://github.com/sstephenson/execjs#readme for more supported runtimes
  # gem 'therubyracer', :platforms => :ruby

  gem 'uglifier', '>= 1.0.3'
end

gem 'jquery-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'

我的捆绑安装显示以下内容:-

C:\Sites\shop>bundle install
Using rake (10.0.3)
Using i18n (0.6.1)
Using multi_json (1.5.0)
Using activesupport (3.2.11)
Using builder (3.0.4)
Using activemodel (3.2.11)
Using erubis (2.7.0)
Using journey (1.0.4)
Using rack (1.4.5)
Using rack-cache (1.2)
Using rack-test (0.6.2)
Using hike (1.2.1)
Using tilt (1.3.3)
Using sprockets (2.2.2)
Using actionpack (3.2.11)
Using mime-types (1.21)
Using polyglot (0.3.3)
Using treetop (1.4.12)
Using mail (2.4.4)
Using actionmailer (3.2.11)
Using arel (3.0.2)
Using tzinfo (0.3.35)
Using activerecord (3.2.11)
Using activeresource (3.2.11)
Using bundler (1.0.22)
Using coffee-script-source (1.4.0)
Using execjs (1.4.0)
Using coffee-script (2.2.0)
Using rack-ssl (1.3.3)
Using json (1.7.6)
Using rdoc (3.12.1)
Using thor (0.17.0)
Using railties (3.2.11)
Using coffee-rails (3.2.2)
Using jquery-rails (2.2.1)
Using pg (0.14.1)
Using rails (3.2.11)
Using sass (3.2.5)
Using sass-rails (3.2.6)
Using uglifier (1.3.0)
Your bundle is complete! Use `bundle show [gemname]` to see where a bundled gem
is installed.

【问题讨论】:

  • 您可以将您的 Gemfile 添加到问题中吗?
  • @jvnill 我已经编辑了这个问题。你能帮帮我吗
  • 那是 Gemfile.lock。 Gemfile 更干净,你可以用它来代替吗?
  • 嗨 Prathamesh,我已经清理了你的一些代码格式,但是请看一下格式指南,它会让你的问题更容易阅读:stackoverflow.com/editing-help
  • 我的 gemfile 有以下内容:- source 'rubygems.org' gem 'rails', '3.2.11' # Bundle edge Rails 代替:# gem 'rails', :git => 'git ://github.com/rails/rails.git' gem 'sqlite3' # Gems 仅用于资产,默认情况下在生产环境中不需要。 group :assets do gem 'sass-rails', '~> 3.2.3' gem 'coffee-rails', '~> 3.2.1' # 更多支持的运行时见github.com/sstephenson/execjs#readme gem 'uglifier', '>= 1.0 .3' 结束 gem 'jquery-rails'

标签: ruby-on-rails database ruby-on-rails-3 postgresql


【解决方案1】:

请试试这个..

 sudo apt-get install postgresql postgresql-client postgresql-contriblibpq-dev

【讨论】:

  • @vijikumar 谢谢你现在它正在工作。你能告诉我如何在 ruby​​ on rail.ie 中启动 postgresql 控制台吗?你能指定命令吗
【解决方案2】:

你跑bundle install了吗?
看起来当前已安装 sqlite3,但未安装 pg

如果您要将数据从 sqlite3 移动到 pg,请查看此 railscast:Migrating to PostgreSQL

【讨论】:

  • 是的,我已经运行了 bundle install C:\Sites\shop>bundle install ... 你的包已经完成了!使用 bundle show [gemname] 查看捆绑 gem 的安装位置。
  • 如何从 ruby​​ on rails 命令提示符启动 postgresql 控制台
  • 我可以在您的 Gemfile 中看到 gem,但在您发布的已安装 gem 列表中看不到。
  • @mind.blank 我已经用已安装的 gem 列表编辑了我的问题,如果需要添加任何 gem,请告诉我
  • 那么不确定。顺便问一下,为什么你们的数据库都在开发?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-12-11
  • 2015-10-23
  • 1970-01-01
  • 2014-06-21
  • 2014-05-20
  • 1970-01-01
相关资源
最近更新 更多