【问题标题】:Trying to deploy to heroku and switching sqlite -> pg- Error when i rake:db尝试部署到 heroku 并切换 sqlite -> pg- 当我 rake:db 时出错
【发布时间】:2013-02-23 16:25:51
【问题描述】:

所以,我正在尝试将在 SQLite3 上本地运行良好的应用程序更改为 Postgresql,以便我可以将其部署到 Heroku。 我查看了各种帖子和教程,并对我的 Gem 文件和 database.yml 文件进行了调整,但是当我尝试 rake:db migrate 时,我收到错误消息:“请安装 postgresql 适配器。”我知道大多数用户在他们的 gemfile 中不包含 gem 'pg' 时都会遇到这种情况,但我确实包含了它。

这是我收到的完整错误消息:http://dpaste.com/hold/972379/

你能帮忙吗?我真的看了几十个帖子,并尝试了每一个配置。

我的 procfile 如下所示:

web: bundle exec thin start -p $PORT

我的 database.yml 看起来像这样:

development:
  adapter: postgresql
  encoding: utf8
  database: project_development
  pool: 5
  username: 
  password:

test: &TEST
  adapter: postgresql
  encoding: utf8
  database: project_test
  pool: 5
  username: 
  password:

production:
  adapter: postgresql
  encoding: utf8
  database: project_production
  pool: 5
  username: 
  password:

我的 gemfile 看起来像这样:

source 'https://rubygems.org'

gem 'rails', '3.2.11'

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

gem 'thin'
group :production do
gem 'pg'
end
group :development, :test do
gem 'sqlite3'
end

# Gems used only for assets and not required
# in production environments by default.

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'

注意:当我运行 bundle install 时,没有出现“使用 pg”,但我认为这是因为它不在生产环境中......仅供参考,以防它很重要

编辑: gem pg 在使用 heroku 生产时似乎运行良好。不知道发生了什么,因为一旦部署,它就不起作用了。这是我的 heroku 日志(我已经取出了我的电子邮件):

2013-02-23T05:37:08+00:00 heroku[api]: Enable Logplex by XXXX@email.com
2013-02-23T05:37:08+00:00 heroku[api]: Release v2 created by XXXX@email.com
2013-02-23T05:37:18+00:00 heroku[slugc]: Slug compilation started
2013-02-23T05:38:28+00:00 heroku[api]: Scale to web=1 by XXXX@email.com
2013-02-23T05:38:28+00:00 heroku[api]: Attach HEROKU_POSTGRESQL_WHITE resource by XXXX@email.com
2013-02-23T05:38:28+00:00 heroku[api]: Release v3 created by XXXX@email.com
2013-02-23T05:38:29+00:00 heroku[api]: Add DATABASE_URL config by XXXX@email.com
2013-02-23T05:38:29+00:00 heroku[api]: Release v4 created by XXXX@email.com
2013-02-23T05:38:29+00:00 heroku[api]: Add  config by XXXX@email.com
2013-02-23T05:38:29+00:00 heroku[api]: Release v5 created by XXXX@email.com
2013-02-23T05:38:29+00:00 heroku[api]: Release v6 created by XXXX@email.com
2013-02-23T05:38:29+00:00 heroku[api]: Deploy cd00730 by XXXX@email.com
2013-02-23T05:38:30+00:00 heroku[slugc]: Slug compilation finished
2013-02-23T05:38:30+00:00 heroku[web.1]: Starting process with command `bundle exec thin start -p 55861`
2013-02-23T05:38:31+00:00 heroku[web.1]: Starting process with command `bundle exec thin start -p 55416`
2013-02-23T05:38:31+00:00 app[web.1]: bash: bundle: command not found
2013-02-23T05:38:32+00:00 heroku[web.1]: Process exited with status 127
2013-02-23T05:38:34+00:00 app[web.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/1/4/rails-3-2-0-rc2-has-been-released. (called from <top (required)> at /app/config/environment.rb:5)
2013-02-23T05:38:34+00:00 app[web.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/1/4/rails-3-2-0-rc2-has-been-released. (called from <top (required)> at /app/config/environment.rb:5)
2013-02-23T05:38:34+00:00 app[web.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/1/4/rails-3-2-0-rc2-has-been-released. (called from <top (required)> at /app/config/environment.rb:5)
2013-02-23T05:38:37+00:00 app[web.1]: >> Using rack adapter
2013-02-23T05:38:37+00:00 app[web.1]: Connecting to database specified by DATABASE_URL
2013-02-23T05:38:37+00:00 app[web.1]: >> Maximum connections set to 1024
2013-02-23T05:38:37+00:00 app[web.1]: >> Thin web server (v1.5.0 codename Knife)
2013-02-23T05:38:37+00:00 app[web.1]: >> Listening on 0.0.0.0:55416, CTRL+C to stop
2013-02-23T05:38:38+00:00 heroku[web.1]: State changed from starting to up
2013-02-23T05:39:00+00:00 heroku[api]: Starting process with command `bundle exec rake db:migrate` by ray.lee@dartmouth.edu
2013-02-23T05:39:02+00:00 heroku[run.3422]: Awaiting client
2013-02-23T05:39:02+00:00 heroku[run.3422]: Starting process with command `bundle exec rake db:migrate`
2013-02-23T05:39:02+00:00 heroku[run.3422]: State changed from starting to up
2013-02-23T05:39:07+00:00 heroku[run.3422]: Client connection closed. Sending SIGHUP to all processes
2013-02-23T05:39:08+00:00 heroku[run.3422]: Process exited with status 0
2013-02-23T05:39:08+00:00 heroku[run.3422]: State changed from up to complete
2013-02-23T05:39:14+00:00 app[web.1]: Started GET "/" for 67.80.190.0 at 2013-02-23 05:39:14 +0000
2013-02-23T05:39:15+00:00 app[web.1]: Processing by LooksController#index as HTML
2013-02-23T05:39:15+00:00 app[web.1]:   Rendered looks/index.html.erb within layouts/application (7.7ms)
2013-02-23T05:39:16+00:00 heroku[router]: at=info method=GET path=/ host=quiet-everglades-5513.herokuapp.com fwd="67.80.190.0" dyno=web.1 queue=0 wait=1ms connect=2ms service=1385ms status=500 bytes=643
2013-02-23T05:39:16+00:00 heroku[router]: at=info method=GET path=/favicon.ico host=quiet-everglades-5513.herokuapp.com fwd="67.80.190.0" dyno=web.1 queue=0 wait=0ms connect=1ms service=7ms status=200 bytes=0
2013-02-23T05:39:16+00:00 app[web.1]: 
2013-02-23T05:39:16+00:00 app[web.1]:     5:   <%= stylesheet_link_tag    "application", :media => "all" %>
2013-02-23T05:39:16+00:00 app[web.1]:     8: </head>
2013-02-23T05:39:16+00:00 app[web.1]: Completed 500 Internal Server Error in 925ms
2013-02-23T05:39:16+00:00 app[web.1]:   app/controllers/looks_controller.rb:7:in `index'
2013-02-23T05:39:16+00:00 app[web.1]:     3: <head>
2013-02-23T05:39:16+00:00 app[web.1]: ActionView::Template::Error (no such file to load -- uglifier
2013-02-23T05:39:16+00:00 app[web.1]:   (in /app/app/assets/javascripts/application.js)):
2013-02-23T05:39:16+00:00 app[web.1]:   app/views/layouts/application.html.erb:6:in `_app_views_layouts_application_html_erb___1708027661978307033_32644180'
2013-02-23T05:39:16+00:00 app[web.1]: 
2013-02-23T05:39:16+00:00 app[web.1]:     6:   <%= javascript_include_tag "application" %>
2013-02-23T05:39:16+00:00 app[web.1]: 
2013-02-23T05:39:16+00:00 app[web.1]:     7:   <%= csrf_meta_tags %>
2013-02-23T05:39:16+00:00 app[web.1]:     9: <body>
2013-02-23T05:39:16+00:00 app[web.1]:     4:   <title>Scout</title>

【问题讨论】:

  • 您是否尝试过从生产组中删除 pg 并将其放入默认组中,以便始终安装它。当你运行 rake 时,你确定你在 prod 环境中运行吗?
  • 嗨。如果我将它放在默认组中,我会收到此错误 (dpaste.com/hold/972650)。老实说,我不完全确定在 prod 环境中运行它是什么意思;之后我运行 db:migrate --trace 。我知道我在使用其他应用程序之前已经遵循了这个一般程序并且它有效。

标签: ruby-on-rails postgresql heroku sqlite web-deployment


【解决方案1】:

您提供的日志文件提到另一个错误

ActionView::Template::Error (no such file to load -- uglifier
  (in /app/app/assets/javascripts/application.js)):
app/views/layouts/application.html.erb:6:in `_app_views_layouts_application_html_erb___1708027661978307033_32644180'

uglifier 是一个用于预编译资产和优化资产的 gem。 在我的应用中,默认情况下它位于 assets 组中,这意味着它在生产中不可用。

我对 Heroku 并不完全熟悉,但他们有一些关于 using the asset pipeline 的信息可能会有所帮助。您还应该确保您使用的是Heroku "Cedar" stack

或者,如果您不使用资产管道,disable it

【讨论】:

    【解决方案2】:

    这是你需要做的:

    1. 从此处https://developer.apple.com/downloads/index.action 下载适用于您的 mac os 版本的命令行工具

    2. 安装您下载的命令行工具

    3. 重启终端

    4. 再次运行 bundle install(使用默认组中的 pg gem)。

    这应该可以消除安装 pg 时遇到的错误。安装后再次运行rake db:migrate,它应该可以工作了。

    【讨论】:

    • 嘿奥斯汀。我真的很感谢所有的帮助。我正在运行雪豹。我应该只安装 XCode (connect.apple.com/cgi-bin/WebObjects/MemberSite.woa/wa/…),因为 Apple 开发网站没有任何 Snow Leopard 的链接,或者我可以通过下载任何用于更高操作系统的命令行来获得
    • 我刚刚下载并安装了它。当我使用默认组中的 'pg' gem 运行 bundle install 时,同样的错误。啊
    • 当我运行 find/ -name pg_config 时,我得到“没有这样的文件或目录”
    • 你需要在你的机器上安装 postgres 来安装 gem:enterprisedb.com/products-services-training/pgdownload#osx
    • 我尝试安装 PostGres (stackoverflow.com/questions/2271069/…) 并通过安装命令行和使用 Homebrew 来遵循一些教程。只是到处遇到错误。不确定我的 Mac 是否有问题,但奇怪的是,当我遵循这些指南时,其他一些应用程序如何能够很好地部署到 heroku,但这个不能。它只是一个简单的表单脚手架
    猜你喜欢
    • 2015-10-22
    • 2023-03-22
    • 1970-01-01
    • 1970-01-01
    • 2020-06-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-11
    相关资源
    最近更新 更多