2012-06-17 39 views
21

Thứ nhất, tôi là một người mới trong đường ray/heroku, vì vậy hãy tha thứ cho người mới trước!Heroku "Chúng tôi xin lỗi, nhưng đã xảy ra sự cố"

Tôi đã làm hướng dẫn Rails (http://guides.rubyonrails.org/getting_started.html) và tạo một ứng dụng "bài đăng" giống như blog, đẩy nó vào github và sau đó được đẩy vào heroku.

Ứng dụng của tôi hoạt động tốt tại địa phương, nhưng khi tôi cố gắng chạy trực tuyến, ứng dụng có "Rất tiếc, đã xảy ra sự cố" trong lỗi phông chữ màu đỏ.

Dưới đây là các bản ghi Heroku:

2012-06-17T18:20:21+00:00 app[web.1]: Started GET "/posts/new" for 24.246.75.91 at 2012-06-17 18:20:21 +0000 
2012-06-17T18:20:21+00:00 app[web.1]: Processing by PostsController#new as HTML 
2012-06-17T18:20:21+00:00 app[web.1]: Rendered posts/_form.html.erb (19.4ms) 
2012-06-17T18:20:21+00:00 app[web.1]: Rendered posts/new.html.erb within layouts/application (32.8ms) 
2012-06-17T18:20:21+00:00 app[web.1]: Completed 500 Internal Server Error in 39ms 
2012-06-17T18:20:21+00:00 app[web.1]: 
2012-06-17T18:20:21+00:00 app[web.1]:  13: 
2012-06-17T18:20:21+00:00 app[web.1]: ActionView::Template::Error (undefined method `name' for #<Post:0x000000043b8e00>): 
2012-06-17T18:20:21+00:00 app[web.1]:  14: <div class="field"> 
2012-06-17T18:20:21+00:00 app[web.1]:  15:  <%= f.label :name %><br /> 
2012-06-17T18:20:21+00:00 app[web.1]:  18: <div class="field"> 
2012-06-17T18:20:21+00:00 app[web.1]:  17: </div> 
2012-06-17T18:20:21+00:00 app[web.1]:  16:  <%= f.text_field :name %> 
2012-06-17T18:20:21+00:00 app[web.1]:  19:  <%= f.label :title %><br /> 
2012-06-17T18:20:21+00:00 app[web.1]: app/views/posts/_form.html.erb:16:in `block in _app_views_posts__form_html_erb___4393344465537738631_33651200' 
2012-06-17T18:20:21+00:00 app[web.1]: app/views/posts/_form.html.erb:1:in `_app_views_posts__form_html_erb___4393344465537738631_33651200' 
2012-06-17T18:20:21+00:00 app[web.1]: app/views/posts/new.html.erb:3:in `_app_views_posts_new_html_erb___263954971377171473_37473500' 
2012-06-17T18:20:21+00:00 app[web.1]: app/controllers/posts_controller.rb:35:in `new' 
2012-06-17T18:20:21+00:00 app[web.1]: 

Tóm lại, f.name là một đối tượng đại diện cho một mục trong cơ sở dữ liệu (như vậy là hầu hết các thông tin cho f)

Các "không xác định phương thức `name '" có vẻ lạ đối với tôi, vì nó hoạt động hoàn toàn cục bộ.

Giả thuyết của tôi là cơ sở dữ liệu không được liên kết đúng giữa heroku và ứng dụng của tôi. Tuy nhiên, tôi không biết làm thế nào tôi có thể giải quyết/kiểm tra vấn đề này.

Ứng dụng của tôi đang sử dụng 'cơ sở dữ liệu được chia sẻ' theo mặc định ngay bây giờ.

Bất kỳ gợi ý nào về kiểm tra nào? Một cái gì đó tôi bị mất?

CHỈNH SỬA 1: cơ sở dữ liệu di chuyển. Bảng 'bài đăng' dường như đã được 'phát hiện'. Đây là một dấu vết:

Running rake db:migrate --trace 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) 
** Invoke db:migrate (first_time) 
** Invoke environment (first_time) 
** Execute environment 
** Invoke db:load_config (first_time) 
** Invoke rails_env (first_time) 
** Execute rails_env 
** Execute db:load_config 
** Execute db:migrate 
Migrating to CreatePosts (20120418005214) 
== CreatePosts: migrating ==================================================== 
-- create_table(:posts) 
rake aborted! 
An error has occurred, this and all later migrations canceled: 

PG::Error: ERROR: relation "posts" already exists 
: CREATE TABLE "posts" ("id" serial primary key, "name" character varying(255), "title" character varying(255), "content" text, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL) 
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/connection_adapters/postgresql_adapter.rb:640:in `async_exec' 
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/connection_adapters/postgresql_adapter.rb:640:in `block in execute' 
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/connection_adapters/abstract_adapter.rb:280:in `block in log' 
/app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.1/lib/active_support/notifications/instrumenter.rb:20:in `instrument' 
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/connection_adapters/abstract_adapter.rb:275:in `log' 
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/connection_adapters/postgresql_adapter.rb:639:in `execute' 
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/connection_adapters/abstract/schema_statements.rb:170:in `create_table' 
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/migration.rb:450:in `block in method_missing' 
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/migration.rb:424:in `block in say_with_time' 
/app/vendor/ruby-1.9.3-p0/lib/ruby/1.9.1/benchmark.rb:280:in `measure' 
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/migration.rb:424:in `say_with_time' 
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/migration.rb:444:in `method_missing' 
/app/db/migrate/20120418005214_create_posts.rb:3:in `change' 
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/migration.rb:393:in `block (2 levels) in migrate' 
/app/vendor/ruby-1.9.3-p0/lib/ruby/1.9.1/benchmark.rb:280:in `measure' 
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/migration.rb:393:in `block in migrate' 
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:118:in `with_connection' 
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/migration.rb:377:in `migrate' 
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/migration.rb:512:in `migrate' 
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/migration.rb:704:in `block (2 levels) in migrate' 
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/migration.rb:759:in `call' 
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/migration.rb:759:in `block in ddl_transaction' 
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/connection_adapters/abstract/database_statements.rb:190:in `transaction' 
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/transactions.rb:208:in `transaction' 
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/migration.rb:759:in `ddl_transaction' 
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/migration.rb:703:in `block in migrate' 
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/migration.rb:684:in `each' 
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/migration.rb:684:in `migrate' 
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/migration.rb:554:in `up' 
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/migration.rb:535:in `migrate' 
/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.1/lib/active_record/railties/databases.rake:153:in `block (2 levels) in <top (required)>' 
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `call' 
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `block in execute' 
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `each' 
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `execute' 
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:158:in `block in invoke_with_call_chain' 
/app/vendor/ruby-1.9.3-p0/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize' 
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:151:in `invoke_with_call_chain' 
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:144:in `invoke' 
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:116:in `invoke_task' 
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `block (2 levels) in top_level' 
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `each' 
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `block in top_level' 
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling' 
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:88:in `top_level' 
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:66:in `block in run' 
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling' 
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:63:in `run' 
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/bin/rake:33:in `<top (required)>' 
/app/vendor/bundle/ruby/1.9.1/bin/rake:19:in `load' 
/app/vendor/bundle/ruby/1.9.1/bin/rake:19:in `<main>' 
Tasks: TOP => db:migrate 

CHỈNH SỬA 2: Cố gắng bỏ cơ sở dữ liệu. lỗi lạ:

19:06:34[~/ED3/ed3/]>heroku run rake db:drop 
Running rake db:drop 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) 
Couldn't drop mtstktqkyx : #<ActiveRecord::StatementInvalid: PG::Error: ERROR: must be owner of database mtstktqkyx 
: DROP DATABASE IF EXISTS "mtstktqkyx"> 

EDIT 3: CreatePosts di cư (từ db/di chuyển /##..##_ create_posts.rb)

class CreatePosts < ActiveRecord::Migration 
    def change 
    create_table :posts do |t| 
     t.string :name 
     t.string :title 
     t.text :content 

     t.timestamps 
    end 
    end 
end 
+1

Rất có thể, bạn đã không di chuyển cơ sở dữ liệu của mình. Tôi không chắc chắn nếu tooloku heroku chăm sóc nó cho bạn. –

+1

nếu bạn không quan tâm đến db trên sản xuất, bạn có thể thử một cái gì đó như 'heroku chạy rake db: thả' và sau đó chạy di chuyển của bạn trên Heroku một lần nữa. –

+0

Chắc chắn trông giống như một vấn đề trong việc di chuyển CreatePosts. Đăng bài đó? – MBHNYC

Trả lời

16

Hóa ra cơ sở dữ liệu của tôi trong heroku đã được tham chiếu sai. Đây là những gì tôi đã làm:

  1. rake db: thả - giết này cả hai thử nghiệm và phát triển bảng
  2. tái tạo hai cơ sở dữ liệu trong posgresql Tôi có nó địa phương cũng
  3. cào db: di chuyển - vì vậy tại thời điểm này localhost đang hoạt động trở lại sau 1.
  4. addons Heroku - chia sẻ cơ sở dữ liệu sẽ được hiển thị
  5. Heroku pg: reset SHARED_DATABASE - không thể làm db: thiết lập lại trong Heroku do phép hành
  6. Heroku chạy rake db: di chuyển - tái di chuyển sản xuất db

Mặc dù chỉ bước 5 và 6 là những người duy nhất giải quyết trực tiếp vấn đề chính của tôi.

Cảm ơn tất cả !!!

+1

Tôi không có bất kỳ ý tưởng những gì tôi chỉ làm nhưng nó đã làm việc. Cảm ơn! – IIllIIll

46

Bạn di chuyển cơ sở dữ liệu của bạn?

thử chạy:

heroku run rake db:migrate 

từ thư mục của dự án của bạn.

+0

Có, nhưng tôi nhận được một cái gì đó như thế này: PG :: Lỗi: LRI: quan hệ "bài viết" đã tồn tại (sẽ thêm dấu vết trong bài orig ngay) – mhz

0

Dường như bạn có nhiều di chuyển để tạo mô hình post. Tôi sẽ xem xét di chuyển trước.

+0

hmmmm, Chỉ có một tệp theo db/migrate/... nếu đó là những gì bạn có ý nghĩa. Các tập tin là trên EDIT 3 – mhz

Các vấn đề liên quan