2017-09-08 18 views
0

私はherokuに自分のアプリをデプロイしましたが、私はあなたがユーザーにナビゲートするたびに私があなたのローカルにはないと主張しています。 "それは地元で完璧に動作するとき。ここでherokuとpostgresのデータベース問題

は、ログには、Herokuの

2017-09-08T20:04:15.359192+00:00 app[web.1]: I, [2017-09-08T20:04:15.359081 #4] INFO -- : [5dd58b3d-a6c1-4a05-a4f8-07a1965f1e05] Started GET "https://stackoverflow.com/users/new" for 184.149.38.253 at 2017-09-08 20:04:15 +0000 
2017-09-08T20:04:15.360162+00:00 app[web.1]: I, [2017-09-08T20:04:15.360086 #4] INFO -- : [5dd58b3d-a6c1-4a05-a4f8-07a1965f1e05] Processing by UsersController#new as HTML 
2017-09-08T20:04:15.379022+00:00 app[web.1]: I, [2017-09-08T20:04:15.378874 #4] INFO -- : [5dd58b3d-a6c1-4a05-a4f8-07a1965f1e05] Completed 500 Internal Server Error in 19ms (ActiveRecord: 11.9ms) 
2017-09-08T20:04:15.379991+00:00 app[web.1]: F, [2017-09-08T20:04:15.379917 #4] FATAL -- : [5dd58b3d-a6c1-4a05-a4f8-07a1965f1e05] 
2017-09-08T20:04:15.380086+00:00 app[web.1]: F, [2017-09-08T20:04:15.380009 #4] FATAL -- : [5dd58b3d-a6c1-4a05-a4f8-07a1965f1e05] ActiveRecord::StatementInvalid (PG::UndefinedTable: ERROR: relation "users" does not exist 
2017-09-08T20:04:15.380087+00:00 app[web.1]: LINE 8:    WHERE a.attrelid = '"users"'::regclass 
2017-09-08T20:04:15.380088+00:00 app[web.1]:           ^
2017-09-08T20:04:15.380090+00:00 app[web.1]: :    SELECT a.attname, format_type(a.atttypid, a.atttypmod), 
2017-09-08T20:04:15.380090+00:00 app[web.1]:      pg_get_expr(d.adbin, d.adrelid), a.attnotnull, a.atttypid, a.atttypmod, 
2017-09-08T20:04:15.380091+00:00 app[web.1]:      c.collname, col_description(a.attrelid, a.attnum) AS comment 
2017-09-08T20:04:15.380091+00:00 app[web.1]:     FROM pg_attribute a 
2017-09-08T20:04:15.380092+00:00 app[web.1]:     LEFT JOIN pg_attrdef d ON a.attrelid = d.adrelid AND a.attnum = d.adnum 
2017-09-08T20:04:15.380092+00:00 app[web.1]:     LEFT JOIN pg_type t ON a.atttypid = t.oid 
2017-09-08T20:04:15.380093+00:00 app[web.1]:     LEFT JOIN pg_collation c ON a.attcollation = c.oid AND a.attcollation <> t.typcollation 
2017-09-08T20:04:15.380094+00:00 app[web.1]:    WHERE a.attrelid = '"users"'::regclass 
2017-09-08T20:04:15.380094+00:00 app[web.1]:     AND a.attnum > 0 AND NOT a.attisdropped 
2017-09-08T20:04:15.380095+00:00 app[web.1]:    ORDER BY a.attnum 
2017-09-08T20:04:15.380096+00:00 app[web.1]:): 
2017-09-08T20:04:15.380146+00:00 app[web.1]: F, [2017-09-08T20:04:15.380086 #4] FATAL -- : [5dd58b3d-a6c1-4a05-a4f8-07a1965f1e05] 
2017-09-08T20:04:15.380220+00:00 app[web.1]: F, [2017-09-08T20:04:15.380159 #4] FATAL -- : [5dd58b3d-a6c1-4a05-a4f8-07a1965f1e05] app/controllers/users_controller.rb:3:in `new' 

コントローラ/ users_controller.rb

class UsersController < ApplicationController 
    def new 
    @user = User.new 
    end 

    def create 
    @user = User.new(user_params) 
    if @user.save 
     redirect_to new_session_url, notice: "Signed up!" 
    else 
     render "new" 
    end 
    end 

    private 
    def user_params 
    params.require(:user).permit(:email, :password, :password_confirmation) 
    end 
end 

モデル/ user.rbからです

class User < ApplicationRecord 
    has_secure_password 
    has_many :lists 
    has_many :items 
end 

Schema.rb

ActiveRecord::Schema.define(version: 20170824180534) do 

    enable_extension "plpgsql" 

    create_table "items", force: :cascade do |t| 
    t.string "item_name" 
    t.integer "item_cost" 
    t.string "item_waste" 
    t.string "item_group" 
    t.datetime "created_at", null: false 
    t.datetime "updated_at", null: false 
    t.string "month" 
    t.integer "user_id" 
    end 

    create_table "lists", force: :cascade do |t| 
    t.integer "income" 
    t.integer "put_into_savings" 
    t.string "month" 
    t.integer "year" 
    t.datetime "created_at", null: false 
    t.datetime "updated_at", null: false 
    t.integer "user_id" 
    end 

    create_table "users", force: :cascade do |t| 
    t.string "email" 
    t.string "password_digest" 
    t.datetime "created_at", null: false 
    t.datetime "updated_at", null: false 
    t.string "name" 
    end 

end 
任意の助けのための先進的で

ビュー/ユーザー/ new.html.erb

<!DOCTYPE html> 
<html lang="en"> 
<head> 
    <meta charset="UTF-8"> 
    <meta name="viewport" content="width=device-width, initial-scale=1.0"> 
    <meta http-equiv="X-UA-Compatible" content="ie=edge"> 
    <title>Document</title> 
</head> 
<body> 

    <nav class="signup_nav"> 
    <img src="http://i.imgur.com/2GrcEK9.png?2" class="UB_logo_1"alt=""> 

    <div onclick="myFunction(); hamburger(this)" class="dropbtn dropdown"> 
     <div class="bar1"></div> 
     <div class="bar2"></div> 
     <div class="bar3"></div> 
    </div> 

    <%= link_to "Home Page", root_url %> 
    <%= link_to "Create a list", new_list_url %> 
    <% if current_user %> 
     <%= link_to 'View your lists', "/lists/#{current_user.id}" %> 
     Signed in as <%= current_user.email %>. <%= link_to "Log out", session_path("current"), :method => :delete %> 
    <% else %> 
     <%= link_to "Log in", new_session_path , {:class=>"nav_left_1"} %> <%= link_to "Sign up", new_user_path , {:class=>"nav_left_2 sign_up_current_nav"} %> 
    <% end %> 
    </nav> 

    <div id="myDropdown" class="dropdown-content"> 
     <%= link_to "Home Page", root_url %></a> 
     <%= link_to "Create a list", new_list_url %></a> 
     <% if current_user %> 
     <%= link_to 'View your lists', "/lists/#{current_user.id}" %> 
     Signed in as <%= current_user.email %>. <%= link_to "Log out", session_path("current"), :method => :delete %> 
     <% else %> 
     <%= link_to "Log in", new_session_path , {:class=>"nav_left_1"} %> <%= link_to "Sign up", new_user_path , {:class=>"nav_left_2"} %> 
     <% end %> 
     </a> 
    </div> 

    <%= form_for @user do |f| %> 
    <% if @user.errors.any? %> 
     <div class="error_messages"> 
     <h2>Form is invalid</h2> 
     <ul> 
      <% @user.errors.full_messages.each do |message| %> 
      <li><%= message %></li> 
      <% end %> 
     </ul> 
     </div> 
    <% end %> 
    <div class="field"> 
     <%= f.label :Email %><br/> 
     <%= f.text_field :email %> 
    </div> 
    <div class="field"> 
     <%= f.label :Username %><br/> 
     <%= f.text_field :name %> 
    </div> 
    <div class="field"> 
     <%= f.label :Password %><br/> 
     <%= f.password_field :password %> 
    </div> 
    <div class="field"> 
     <%= f.label :Password_confirmation %><br/> 
     <%= f.password_field :password_confirmation %> 
    </div> 
    <div class="actions"><%= f.submit %></div> 
    <% end %> 

</body> 
</html> 

おかげで、私はそれを本当に感謝しています。

+0

リストモデルとアイテムモデルにはbelongs_to関係が定義されていますか? –

+0

@RockwellRiceはい、両方とも 'belongs_to:user'を持っています – firewire167

答えて

0

あなたのエラーメッセージにこの行から判断:

ActiveRecord::StatementInvalid (PG::UndefinedTable: ERROR: relation "users" does not exist

移行はHerokuの上で正常に実行されなかったように私には思えます。

私は

heroku rake db:reset ('heroku run rake db:reset' if you're on cedar)

heroku rake db:migrate ('heroku run rake db:migrate' if you're on cedar)

を実行し、それは私を取得する場所を確認しようとするだろう。

関連する問題