【问题标题】:RoR application deploymentRoR 应用程序部署
【发布时间】:2021-12-16 14:45:12
【问题描述】:

在我将应用程序部署到 heroku 后,我正在运行“heroku run rake db:migrate”,我得到了这个:

$>>heroku 运行 rake db:migrate

Running rake db:migrate attached to terminal... up, run.1
DEPRECATION WARNING: You have Rails 2.3-style plugins in vendor/plugins! Support for these plugins will be removed in Rails 4.0. Move them out and bundle them in your Gemfile, or fold them in to your app as lib/myplugin/* and config/initializers/myplugin.rb. See the release notes for more on this: http://weblog.rubyonrails.org/2012/01/04/rails-3-2-0-rc2-has-been-released. (called from <top (required)> at /app/Rakefile:7)
DEPRECATION WARNING: You have Rails 2.3-style plugins in vendor/plugins! Support for these plugins will be removed in Rails 4.0. Move them out and bundle them in your Gemfile, or fold them in to your app as lib/myplugin/* and config/initializers/myplugin.rb. See the release notes for more on this: http://weblog.rubyonrails.org/2012/01/04/rails-3-2-0-rc2-has-been-released. (called from <top (required)> at /app/Rakefile:7)
DEPRECATION WARNING: You have Rails 2.3-style plugins in vendor/plugins! Support for these plugins will be removed in Rails 4.0. Move them out and bundle them in your Gemfile, or fold them in to your app as lib/myplugin/* and config/initializers/myplugin.rb. See the release notes for more on this: http://weblog.rubyonrails.org/2012/01/04/rails-3-2-0-rc2-has-been-released. (called from <top (required)> at /app/Rakefile:7)
rake aborted!
Please install the postgresql adapter: `gem install activerecord-postgresql-adapter` (pg is not part of the bundle. Add it to Gemfile.)

Tasks: TOP => db:migrate => db:load_config
(See full trace by running task with --trace)

我尝试安装提到的 gem,但没有任何反应。我正在使用 rails3 和 ruby​​ 1.9.3,我的 database.yml 文件包含:

# SQLite version 3.x
#   gem install sqlite3
#
#   Ensure the SQLite 3 gem is defined in your Gemfile
#   gem 'sqlite3'
development:
  adapter: sqlite3
  database: db/development.sqlite3
  pool: 5
  timeout: 5000

# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
  adapter: sqlite3
  database: db/test.sqlite3
  pool: 5
  timeout: 5000

production:
  adapter: sqlite3
  database: db/production.sqlite3
  pool: 5
  timeout: 5000

我该如何解决这个错误?

编辑:

正在运行 $>>sudo gem install pg -v '0.13.2'

Building native extensions.  This could take a while...
ERROR:  Error installing pg:
    ERROR: Failed to build gem native extension.

        /usr/bin/ruby1.8 extconf.rb
checking for pg_config... no
No pg_config... trying anyway. If building fails, please try again with
 --with-pg-config=/path/to/pg_config
checking for libpq-fe.h... no
Can't find the 'libpq-fe.h header
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers.  Check the mkmf.log file for more
details.  You may need configuration options.

Provided configuration options:
    --with-opt-dir
    --without-opt-dir
    --with-opt-include
    --without-opt-include=${opt-dir}/include
    --with-opt-lib
    --without-opt-lib=${opt-dir}/lib
    --with-make-prog
    --without-make-prog
    --srcdir=.
    --curdir
    --ruby=/usr/bin/ruby1.8
    --with-pg
    --without-pg
    --with-pg-dir
    --without-pg-dir
    --with-pg-include
    --without-pg-include=${pg-dir}/include
    --with-pg-lib
    --without-pg-lib=${pg-dir}/lib
    --with-pg-config
    --without-pg-config
    --with-pg_config
    --without-pg_config


Gem files will remain installed in /usr/lib/ruby/gems/1.8/gems/pg-0.13.2 for inspection.
Results logged to /usr/lib/ruby/gems/1.8/gems/pg-0.13.2/ext/gem_make.out

我收到此错误。我再次使用 1.9.3 版本的 ruby​​。

【问题讨论】:

  • 您是在尝试使用 postgresql 还是 sqlite3?

标签: ruby-on-rails


【解决方案1】:

您的 database.yml 已设置为使用 sqlite3。

如果你想使用 postgresql,你需要先在你的电脑上安装 postgres。

对于 Linux:

sudo apt-get install postgresql

对于 Max OS X:

brew install postgresql

让你先安装homebrew

heroku 在部署时自动生成 database.yml。读起来像:你在 database.yml 中放什么并不重要,这对我来说很好,因为我可以将它包含在 git 中,而不必担心生产数据库密码。

然后通过将其放入您的 Gemfile 中来安装 pg gem:

gem 'pg', :require => 'pg'

如果您使用的是旧版本的 Rails,请使用 gem install 方法。

【讨论】:

  • Eric,Heroku 总是使用 Postgres,不管你在 database.yml 中输入了什么。但除非您使用自己的 SQL,否则在本地运行 SQLite 和在 Heroku 上运行 Postgres 并没有什么坏处。 OP 的原始问题与 Heroku 部署有关;现在他在本地安装 Postgres 时遇到了另一个问题,这与最初的问题不同。
  • 嘿,我在这里找到了一个可行的解决方案:stackoverflow.com/questions/6040583/…
【解决方案2】:

尝试将“pg”gem 添加到您的 Gemfile(然后 bundle install)。

【讨论】:

  • 如何配置它以使用 postgersql?
  • @EricSites,Heroku 总是使用 Postgres,无论你在 database.yml 中输入什么。
  • @TestTest,如果您只想让您的应用程序尽快运行,您可以随时bundle install在安装了 Postgres 的机器上。最好让它也在你的开发机器上运行,但这与你最初寻求帮助的问题不同。或者,你可以手动破解Gemfile.lock——我之前在 Windows 上开发并部署到 Heroku 时已经这样做了,因为我需要使用的一些 gem 无法在 Windows 上安装。
猜你喜欢
  • 2018-08-18
  • 1970-01-01
  • 1970-01-01
  • 2014-11-25
  • 2011-01-25
  • 2011-04-23
  • 2012-03-24
  • 1970-01-01
相关资源
最近更新 更多