heroku和postgres的数据库问题

时间:2017-09-08 20:12:03

标签: ruby-on-rails postgresql heroku

我刚刚将我的应用程序部署到了heroku,我在heroku上遇到了一个问题,我没有在我的本地出现,每当你导航到用户/新的时候你只是得到错误“出错了”当它工作完全正常在当地。

以下是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 "/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>

感谢先进的任何帮助,我真的很感激。

1 个答案:

答案 0 :(得分:0)

从错误消息中的这一行判断:

  

ActiveRecord :: StatementInvalid(PG :: UndefinedTable:ERROR:relation&#34; users&#34;不存在

在我看来,迁移在Heroku上运行不正确。

我会尝试运行

  

heroku rake db:reset(&#39; heroku run rake db:reset&#39;如果你在雪松上)

     

heroku rake db:migrate(&#39; heroku run rake db:migrate&#39;如果你在雪松上)

并看看它在哪里。

相关问题