在heroku上的rails上部署ruby后丢失的所有数据

时间:2014-04-29 18:12:33

标签: ruby-on-rails database heroku sqlite

将我的应用部署到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数据库。

3 个答案:

答案 0 :(得分: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

答案 1 :(得分:0)

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

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

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

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

有关更多信息,请参阅Heroku docs

答案 2 :(得分:0)

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

原因是我没有将本地数据库传输到heroku数据库。