【问题标题】:all data lost after deploying ruby on rails on heroku在heroku上的rails上部署ruby后所有数据丢失
【发布时间】:2014-06-15 20:03:58
【问题描述】:

在我将我的应用程序部署到 Heroku 后,一切看起来都很好,但我的所有数据都丢失了,我的 Heroku 应用程序页面上没有数据。以下是我的heroku日志:

2014-04-29T17:50:58.886649+00:00 app[web.1]:   Rendered layouts/_footer.erb (0.0ms)
2014-04-29T17:50:58.890068+00:00 app[web.1]: Completed 200 OK in 26ms (Views: 11.2ms | ActiveRecord: 12.3ms)
2014-04-29T17:50:59.255494+00:00 heroku[router]: at=info method=GET path=/assets/bg_gulanyu.jpg host=ancient-hamlet-8143.herokuapp.com request_id=a0906a17-2017-48fc-93b3-3375f0a3e658 fwd="216.151.31.224" dyno=web.1 connect=2ms service=7ms status=304 bytes=236
2014-04-29T17:50:59.669323+00:00 heroku[router]: at=info method=GET path=/assets/controls.png host=ancient-hamlet-8143.herokuapp.com request_id=d9d34b08-58ea-423d-b630-25239be7ab74 fwd="216.151.31.224" dyno=web.1 connect=2ms service=7ms status=304 bytes=236
2014-04-29T17:50:59.682317+00:00 heroku[router]: at=info method=GET path=/assets/glyphicons-halflings-regular.woff host=ancient-hamlet-8143.herokuapp.com request_id=ff27501f-7281-4519-a60b-1eca87258d41 fwd="216.151.31.224" dyno=web.1 connect=3ms service=10ms status=304 bytes=236
2014-04-29T17:50:59.687130+00:00 heroku[router]: at=info method=GET path=/assets/bx_loader.gif host=ancient-hamlet-8143.herokuapp.com request_id=eae630fc-db55-486a-b583-c1822295acce fwd="216.151.31.224" dyno=web.1 connect=3ms service=9ms status=304 bytes=236
2014-04-29T17:51:01.494615+00:00 heroku[router]: at=info method=GET path=/spots host=ancient-hamlet-8143.herokuapp.com request_id=052c362a-4a9f-4674-a3a7-ac20acbf9217 fwd="216.151.31.224" dyno=web.1 connect=9ms service=33ms status=304 bytes=355
2014-04-29T17:51:01.451084+00:00 app[web.1]: Started GET "/spots" for 216.151.31.224 at 2014-04-29 17:51:01 +0000
2014-04-29T17:51:01.471413+00:00
 app[web.1]:   Rendered layouts/_header.erb (0.5ms)
2014-04-29T17:51:01.465226+00:00 app[web.1]:   Rendered layouts/_spotItem.html.erb (2.6ms)
2014-04-29T17:51:01.471816+00:00 app[web.1]:   Rendered layouts/_footer.erb (0.0ms)
2014-04-29T17:51:01.454272+00:00 app[web.1]: Processing by SpotsController#index as HTML
2014-04-29T17:51:01.465885+00:00 app[web.1]:   Rendered spots/index.html.erb within layouts/application (3.5ms)
2014-04-29T17:51:01.474967+00:00 app[web.1]: Completed 200 OK in 21ms (Views: 11.0ms | ActiveRecord: 8.1ms)
2014-04-29T17:51:01.471593+00:00 app[web.1]:   Rendered layouts/_sidebar.erb (0.0ms)
2014-04-29T17:51:01.957138+00:00 heroku[router]: at=info method=GET path=/assets/bg_gulanyu.jpg host=ancient-hamlet-8143.herokuapp.com request_id=7f0d0d8a-8ab1-4115-b87a-d3b9056abd6a fwd="216.151.31.224" dyno=web.1 connect=32ms service=32ms status=304 bytes=236
2014-04-29T17:51:02.235561+00:00 heroku[router]: at=info method=GET path=/assets/glyphicons-halflings-regular.woff host=ancient-hamlet-8143.herokuapp.com request_id=b1ecc5d5-8442-44e4-9d6d-b65b68b43e9a fwd="216.151.31.224" dyno=web.1 connect=3ms service=9ms status=304 bytes=236
2014-04-29T17:51:05.260056+00:00 heroku[router]: at=info method=GET path=/spots/new host=ancient-hamlet-8143.herokuapp.com request_id=e3af6e0a-6fa0-4de3-8397-d57a884962de fwd="216.151.31.224" dyno=web.1 connect=16ms service=89ms status=500 bytes=939
2014-04-29T17:51:05.165888+00:00 app
[web.1]: Started GET "/spots/new" for 216.151.31.224 at 2014-04-29 17:51:05 +0000
2014-04-29T17:51:05.237761+00:00 app[web.1]: 
2014-04-29T17:51:05.237764+00:00 app[web.1]: ActionView::Template::Error (undefined method `image2' for #<Spot:0x00000003f9ac88>):
2014-04-29T17:51:05.237765+00:00 app[web.1]:     37:             <th><%= f.label :image1 %></th>
2014-04-29T17:51:05.169475+00:00 app[web.1]: Processing by SpotsController#new as HTML
2014-04-29T17:51:05.237767+00:00 app[web.1]:     38:             <td><%= f.text_field :image, :class => 'form-control' %></td>
2014-04-29T17:51:05.237770+00:00 app[web.1]:     40:             <td><%= f.text_field :image2, :class => 'form-control' %></td>
2014-04-29T17:51:05.237769+00:00 app[web.1]:     39:             <th><%= f.label :image2 %></th>
2014-04-29T17:51:05.237777+00:00 app[web.1]:   app/views/spots/_form.html.erb:40:in `block in _app_views_spots__form_html_erb__916336334634292621_40913960'
2014-04-29T17:51:05.237775+00:00 app[web.1]:     43:           </thead>
2014-04-29T17:51:05.235228+00:00 app[web.1]:   Rendered spots/_form.html.erb (41.0ms)
2014-04-29T17:51:05.235301+00:00 app[web.1]:   Rendered spots/new.html.erb within layouts/application (42.2ms)
2014-04-29T17:51:05.237772+00:00 app[web.1]:     41:             
2014-04-29T17:51:05.237778+00:00 app[web.1]:   app/views/spots/_form.html.erb:1:in `_app_views_spots__form_html_erb__916336334634292621_40913960'
2014-04-29T17:51
:05.237780+00:00 app[web.1]:   app/views/spots/new.html.erb:3:in `_app_views_spots_new_html_erb___1927106455304175595_40887520'
2014-04-29T17:51:05.237785+00:00 app[web.1]: 
2014-04-29T17:51:05.237774+00:00 app[web.1]:     42:           </tr>
2014-04-29T17:51:05.237783+00:00 app[web.1]: 
2014-04-29T17:51:05.237782+00:00 app[web.1]:   app/controllers/spots_controller.rb:36:in `new'
2014-04-29T17:51:05.235524+00:00 app[web.1]: Completed 500 Internal Server Error in 66ms
2014-04-29T17:51:06.662376+00:00 heroku[router]: at=info method=GET path=/spots/new host=ancient-hamlet-8143.herokuapp.com request_id=219d96ee-ee05-455a-ba2f-e5586109d70e fwd="216.151.31.224" dyno=web.1 connect=2ms service=26ms status=500 bytes=939
2014-04-29T17:51:06.630165+00:00 app[web.1]: Started GET "/spots/new" for 216.151.31.224 at 2014-04-29 17:51:06 +0000
2014-04-29T17:51:06.644934+00:00 app[web.1]:   Rendered spots/_form.html.erb (4.0ms)
2014-04-29T17:51:06.645390+00:00 app[web.1]: Completed 500 Internal Server Error in 11ms
2014-04-29T17:51:06.647778+00:00 app[web.1]:     37:             <th><%= f.label :image1 %></th>
2014-04-29T17:51:06.634478+00:00 app[web.1]: Processing by SpotsController#new as HTML
2014-04-29T17:51:06.645149+00:00 app[web.1]:   Rendered spots/new.html.erb within layouts/application (4.4ms)
2014-04-29T17:51:06.647772+00:00 app[web.1]: 
2014-04-29T17:51:06.647776+00:00 app[web.1]: ActionView::Template::Error (undefined method `im
age2' for #<Spot:0x00000003f2cb48>):
2014-04-29T17:51:06.647783+00:00 app[web.1]:     40:             <td><%= f.text_field :image2, :class => 'form-control' %></td>
2014-04-29T17:51:06.647791+00:00 app[web.1]:   app/views/spots/_form.html.erb:1:in `_app_views_spots__form_html_erb__916336334634292621_40913960'
2014-04-29T17:51:06.647780+00:00 app[web.1]:     38:             <td><%= f.text_field :image, :class => 'form-control' %></td>
2014-04-29T17:51:06.647781+00:00 app[web.1]:     39:             <th><%= f.label :image2 %></th>
2014-04-29T17:51:06.647794+00:00 app[web.1]:   app/controllers/spots_controller.rb:36:in `new'
2014-04-29T17:51:06.647784+00:00 app[web.1]:     41:             
2014-04-29T17:51:06.647786+00:00 app[web.1]:     42:           </tr>
2014-04-29T17:51:06.647787+00:00 app[web.1]:     43:           </thead>
2014-04-29T17:51:06.647795+00:00 app[web.1]: 
2014-04-29T17:51:06.647789+00:00 app[web.1]:   app/views/spots/_form.html.erb:40:in `block in _app_views_spots__form_html_erb__916336334634292621_40913960'
2014-04-29T17:51:06.647792+00:00 app[web.1]:   app/views/spots/new.html.erb:3:in `_app_views_spots_new_html_erb___1927106455304175595_40887520'
2014-04-29T17:51:06.647797+00:00 app[web.1]: 
2014-04-29T17:51:07.889739+00:00 heroku[router]: at=info method=GET path=/spots/new host=ancient-hamlet-8143.herokuapp.com request_id=cb7d590c-86cf-404e-835d-f9b758b88e1d fwd="216.151.31.224" dyno=web.1 connect=15ms ser
vice=32ms status=500 bytes=939
2014-04-29T17:51:07.864220+00:00 app[web.1]:   Rendered spots/_form.html.erb (3.7ms)
2014-04-29T17:51:07.849102+00:00 app[web.1]: Started GET "/spots/new" for 216.151.31.224 at 2014-04-29 17:51:07 +0000
2014-04-29T17:51:07.852450+00:00 app[web.1]: Processing by SpotsController#new as HTML
2014-04-29T17:51:07.866822+00:00 app[web.1]:     40:             <td><%= f.text_field :image2, :class => 'form-control' %></td>
2014-04-29T17:51:07.866824+00:00 app[web.1]:     41:             
2014-04-29T17:51:07.866821+00:00 app[web.1]:     39:             <th><%= f.label :image2 %></th>
2014-04-29T17:51:07.866819+00:00 app[web.1]:     38:             <td><%= f.text_field :image, :class => 'form-control' %></td>
2014-04-29T17:51:07.864421+00:00 app[web.1]:   Rendered spots/new.html.erb within layouts/application (4.0ms)
2014-04-29T17:51:07.864547+00:00 app[web.1]: Completed 500 Internal Server Error in 12ms
2014-04-29T17:51:07.866792+00:00 app[web.1]: 
2014-04-29T17:51:07.866796+00:00 app[web.1]: ActionView::Template::Error (undefined method `image2' for #<Spot:0x00000004630958>):
2014-04-29T17:51:07.866818+00:00 app[web.1]:     37:             <th><%= f.label :image1 %></th>
2014-04-29T17:51:07.866825+00:00 app[web.1]:     42:           </tr>
2014-04-29T17:51:07.866834+00:00 app[web.1]:     43:           </thead>
2014-04-29T17:51:07.866836+00:00 app[web.1]:   app/views/spots/_form.html.erb:40:in `block in _app_views_spots__form_html_erb__916336334634292621_40913960'
2014-04-29T17:51:07.866837+00:00 app[web.1]:   app/views/spots/_form.html.erb:1:in `_app_views_spots__form_html_erb__916336334634292621_40913960'
2014-04-29T17:51:07.866838+00:00 app[web.1]:   app/views/spots/new.html.erb:3:in `_app_views_spots_new_html_erb___1927106455304175595_40887520'
2014-04-29T17:51:07.866840+00:00 app[web.1]:   app/controllers/spots_controller.rb:36:in `new'
2014-04-29T17:51:07.866841+00:00 app[web.1]: 
2014-04-29T17:51:07.866842+00:00 app[web.1]: 
2014-04-29T17:51:09.134976+00:00 heroku[router]: at=info method=GET path=/spots/new host=ancient-hamlet-8143.herokuapp.com request_id=e6898201-d655-4b01-818c-bde4d5e42ef0 fwd="216.151.31.224" dyno=web.1 connect=11ms service=36ms status=500 bytes=939
2014-04-29T17:51:09.104382+00:00 app[web.1]: Completed 500 Internal Server Error in 11ms
2014-04-29T17:51:09.107047+00:00 app[web.1]:     39:             <th><%= f.label :image2 %></th>
2014-04-29T17:51:09.107039+00:00 app[web.1]: 
2014-04-29T17:51:09.107042+00:00 app[web.1]: ActionView::Template::Error (undefined method `image2' for #<Spot:0x00000004c2aca0>):
2014-04-29T17:51:09.107044+00:00 app[web.1]:     37:             <th><%= f.label :image1 %></th>
2014-04-29T17:51:09.107045+00:00 app[web.1]:     38:             <td><%= f.text_field :image, :class => 'form-control' %></td>
2014-04-29T17:51:09.089624+00:00 app[web.1]: Started GET "/spots/new" for 216.151.31.224 at 2014-04-29 17:51:09 +0000
2014-04-29T17:51:09.104086+00:00 app[web.1]:   Rendered spots/_form.html.erb (4.1ms)
2014-04-29T17:51:09.104245+00:00 app[web.1]:   Rendered spots/new.html.erb within layouts/application (4.5ms)
2014-04-29T17:51:09.107049+00:00 app[web.1]:     40:             <td><%= f.text_field :image2, :class => 'form-control' %></td>
2014-04-29T17:51:09.107051+00:00 app[web.1]:     41:             
2014-04-29T17:51:09.107053+00:00 app[web.1]:     42:           </tr>
2014-04-29T17:51:09.107055+00:00 app[web.1]:     43:           </thead>
2014-04-29T17:51:09.107056+00:00 app[web.1]:   app/views/spots/_form.html.erb:40:in `block in _app_views_spots__form_html_erb__916336334634292621_40913960'
2014-04-29T17:51:09.107058+00:00 app[web.1]:   app/views/spots/_form.html.erb:1:in `_app_views_spots__form_html_erb__916336334634292621_40913960'
2014-04-29T17:51:09.107060+00:00 app[web.1]:   app/views/spots/new.html.erb:3:in `_app_views_spots_new_html_erb___1927106455304175595_40887520'
2014-04-29T17:51:09.107061+00:00 app[web.1]:   app/controllers/spots_controller.rb:36:in `new'
2014-04-29T17:51:09.107062+00:00 app[web.1]: 
2014-04-29T17:51:09.107064+00:00 app[web.1]: 
2014-04-29T17:51:09.092806+00:00 app[web.1]: Processing by SpotsController#new as HTML

但该应用在我的本地机器上运行良好,以下是屏幕截图:

■ 列表页: https://www.dropbox.com/s/cdvb46fv2t7ootm/Screenshot%202014-04-30%2002.03.18.png

=========================================

使用 gem yaml_db 解决的问题。
https://coderwall.com/p/90qymq

原因是我没有将本地数据库转移到 heroku 数据库。

【问题讨论】:

  • 你跑过heroku run rake db:migrate吗?
  • 是的,我做到了。并没有工作。
  • 我确实运行了 heroku run rake db:migrate 并且没有工作:)
  • 似乎image2 未定义为您记录。您如何在特定记录上定义它?你能告诉我 Spot 表中有哪些列吗?
  • @MattLeonard 这是我的 sqlite DB 屏幕截图:cl.ly/image/1X2F2i0t3l2Y/o。这是 schema.rb:cl.ly/image/3t3N3k0h380s/o。谢谢!

标签: ruby-on-rails database heroku sqlite


【解决方案1】:

在您的情况下,您只是将代码推送到 Heroku,而不是数据库。

可能你在开发时有 sqlite 或任何数据库,但 Heroku 只支持 postgres。

You have to import your data from local to heroku using seeds file or 
migration file.

或者

May be you forgot to run rake db:create and rake db:migrate to create db.

Generating Seeds From Existing Data

【讨论】:

  • 哦,我在执行 rake db:migrate 之前没有运行 rake db:create。我还没有尝试过,因为我使用 yaml_db 解决了我的问题。
【解决方案2】:

从您的评论中我可以看出您使用 sqlite 作为数据库,这是一个文件系统数据库。

Heroku 文件系统是只读的,这意味着您不能动态写入文件系统以进行半永久存储。 Heroku 不支持写入 SQLite 或 GDBM 等文件系统数据库。

此外,如果您在 Heroku 上选择多个测功机,则不建议在 Heroku 上保存和检索任何文件。因为当您保存文件时,它可能会保存在一个测功机上,而当您尝试读取它时,请求可能会转到另一个测功机。

对于数据库,请尝试使用 Heroku 提供的 PostgreSQL 数据库而不是文件系统数据库。

更多信息请参考Heroku docs

【讨论】:

    【解决方案3】:

    使用 gem yaml_db 解决的问题。
    https://coderwall.com/p/90qymq

    原因是我没有将本地数据库转移到 heroku 数据库。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-08-25
      • 2017-07-28
      • 1970-01-01
      • 2012-04-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多