将Rails 3.1应用程序部署到heroku错误(sqlite3-> Postgresql)?

时间:2011-11-27 13:00:12

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

我在部署rails 3.1时遇到问题。应用程序到heroku。

经过一番研究,我发现问题背后的主要原因是 - http://devcenter.heroku.com/articles/how-do-i-use-sqlite3-for-development

更改我的gem文件后:

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

仍然是“我们很抱歉,但出了点问题。”页面错误。

这是日志文件:

 ←[36m2011-11-26T16:34:31+00:00 heroku[api]:←[0m Add-on add logging:basic by emil
 s.veveris@thrillengine.com
 ←[36m2011-11-26T16:34:31+00:00 heroku[api]:←[0m Release v2 created by emils.veve
 ris@thrillengine.com
 ←[36m2011-11-26T16:34:31+00:00 heroku[api]:←[0m Add-on update shared-database
 ←[36m2011-11-26T16:34:31+00:00 heroku[api]:←[0m Release v3 created by emils.veve
 ris@thrillengine.com
 ←[33m2011-11-26T16:43:15+00:00 heroku[slugc]:←[0m Slug compilation started
 ←[36m2011-11-26T16:44:17+00:00 heroku[api]:←[0m Deploy 277a3f4 by emils.veveris@
 thrillengine.com
 ←[36m2011-11-26T16:44:17+00:00 heroku[api]:←[0m Release v4 created by emils.veve
  ris@thrillengine.com
 ←[32m2011-11-26T16:44:18+00:00 heroku[web.1]:←[0m State changed from created to
  starting
 ←[33m2011-11-26T16:44:18+00:00 heroku[slugc]:←[0m Slug compilation finished
 ←[32m2011-11-26T16:44:28+00:00 heroku[web.1]:←[0m State changed from starting to
  up
 ←[35m2011-11-26T17:09:51+00:00 heroku[nginx]:←[0m 81.198.241.178 - - [26/Nov/201
  1:09:09:51 -0800] "GET / HTTP/1.1" 500 728 "-" "Mozilla/5.0 (Windows NT 5.1; rv:
  8.0) Gecko/20100101 Firefox/8.0" stormy-night-6239.heroku.com
 ←[32m2011-11-26T18:12:59+00:00 heroku[web.1]:←[0m Idling
 ←[32m2011-11-26T18:13:00+00:00 heroku[web.1]:←[0m State changed from up to down
 ←[32m2011-11-26T18:13:00+00:00 heroku[web.1]:←[0m State changed from down to cre
  ated
 ←[32m2011-11-26T18:13:01+00:00 heroku[web.1]:←[0m State changed from created to
 starting
 ←[32m2011-11-26T18:13:02+00:00 heroku[web.1]:←[0m Stopping process with SIGTERM
 ←[32m2011-11-26T18:13:02+00:00 app[web.1]:←[0m >> Stopping ...
 ←[32m2011-11-26T18:13:02+00:00 heroku[web.1]:←[0m Process exited
 ←[32m2011-11-26T18:13:11+00:00 app[web.1]:←[0m >> Thin web server (v1.2.6 codena
  me Crazy Delicious)
 ←[32m2011-11-26T18:13:11+00:00 app[web.1]:←[0m >> Maximum connections set to 102
  4
 ←[32m2011-11-26T18:13:11+00:00 app[web.1]:←[0m >> Listening on 0.0.0.0:29604, CT
 RL+C to stop
 ←[32m2011-11-26T18:13:12+00:00 heroku[web.1]:←[0m State changed from starting to
 up
 ←[32m2011-11-26T19:16:24+00:00 heroku[web.1]:←[0m Idling
 ←[32m2011-11-26T19:16:25+00:00 heroku[web.1]:←[0m State changed from up to down
 ←[32m2011-11-27T11:29:48+00:00 heroku[web.1]:←[0m Unidling
 ←[32m2011-11-27T11:29:48+00:00 heroku[web.1]:←[0m State changed from down to cre
 ated
 ←[32m2011-11-27T11:29:50+00:00 heroku[web.1]:←[0m State changed from created to
 starting
 ←[32m2011-11-27T11:29:53+00:00 heroku[web.1]:←[0m Starting process with command
 `thin -p 16668 -e production -R /home/heroku_rack/heroku.ru start`
 ←[32m2011-11-27T11:29:59+00:00 app[web.1]:←[0m >> Thin web server (v1.2.6 codena
 me Crazy Delicious)
 ←[32m2011-11-27T11:29:59+00:00 app[web.1]:←[0m >> Maximum connections set to 102
 4
 ←[32m2011-11-27T11:29:59+00:00 app[web.1]:←[0m >> Listening on 0.0.0.0:16668, CT
 RL+C to stop
 ←[32m2011-11-27T11:30:00+00:00 heroku[web.1]:←[0m State changed from starting to
 up
 ←[31m2011-11-27T11:30:01+00:00 heroku[router]:←[0m GET stormy-night-6239.heroku.
 com/ dyno=web.1 queue=0 wait=0ms service=230ms status=500 bytes=728

我没有看到任何错误。

我也尝试过运行heroku rake db:migrate 并且gotthis错误:

rake aborted!
An error has occurred, this and all later migrations canceled:

PGError: ERROR:  column "location_id" of relation "trips" already exists
: ALTER TABLE "trips" ADD COLUMN "location_id" integer

目前我真的不明白做什么,在哪里看以及要改变什么。 在我的本地机器上一切正常,很难!

感谢任何帮助/ ROR新手!

更新:

在heroku rake db:reset

之后
 Couldn't drop dahrzbhlza : #<ActiveRecord::StatementInvalid: PGError: ERROR:  mu
 st be owner of database dahrzbhlza
 : DROP DATABASE IF EXISTS "dahrzbhlza">
 dahrzbhlza already exists
 -- create_table("categories", {:force=>true})
 -> 0.0595s
 -- create_table("categories_trips", {:id=>false, :force=>true})
 -> 0.0031s
 -- create_table("details", {:force=>true})
 -> 0.0129s
 -- create_table("details_trips", {:id=>false, :force=>true})
 -> 0.0042s
 -- create_table("images", {:force=>true})
 -> 0.1982s
 -- create_table("locations", {:force=>true})
 -> 0.1065s
 -- create_table("trips", {:force=>true})
 -> 0.0422s
 -- create_table("users", {:force=>true})
 -> 0.1486s
 -- add_index("users", ["email"], {:name=>"index_users_on_email", :unique=>true})

 -> 0.0102s
 -- initialize_schema_migrations_table()
 -> 0.0017s
 -- assume_migrated_upto_version(20111116120713, ["/app/db/migrate"])
 -> 0.0091s

在heroku rake db:migrate:redo

之后
 ==  AddTitleToImages: reverting ===============================================
 -- remove_column("images", :title)
 -> 0.0058s
 ==  AddTitleToImages: reverted (0.0059s) ======================================

 ==  AddTitleToImages: migrating ===============================================
 -- add_column(:images, :title, :string)
 -> 0.0032s
 ==  AddTitleToImages: migrated (0.0033s) ======================================

另一个问题 - 为什么只迁移上面的那两列 - 不是全部?

3 个答案:

答案 0 :(得分:1)

尝试通过从本地计算机推送工作副本来重建数据库。你可以使用taps,就像这样

#On your local machine, that has a working database
$heroku db:push

一旦它们相同,您的迁移应该开始变得更有意义。

答案 1 :(得分:1)

你要做的另一件事是转移到Rails 3.1站点的Cedar堆栈 - 你从那个堆栈跟踪中运行Bamboo - heroku create --stack cedar然后重新启动。你也不需要你的gemfile中列出的rubyracer gem,它非常需要内存,而且不再需要Cedar。

答案 2 :(得分:0)

试试这个

group :production do
  # gems specifically for Heroku go here
  gem 'therubyracer-heroku', '0.8.1.pre3'
  gem "pg"
end