简体   繁体   English

Heroku和Postgres的数据库问题

[英]Database issue with heroku and postgres

I have just deployed my app to heroku and I am getting an issue on heroku that I am not getting on my local, whenever you navigate to users/new you just get the error "Something went wrong" when it works perfectly fine on local. 我刚刚将应用程序部署到了heroku上,但是在heroku上却遇到了一个问题,那就是我不在本地环境中使用,每当您导航到用户/新用户时,当在本地环境中运行正常时,您都会收到错误消息“ Something出了问题”。

Here are the logs from 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'

controllers/users_controller.rb controllers / 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

model/user.rb 型号/user.rb

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

Schema.rb 模式.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

views/users/new.html.erb views / users / 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>

Thanks in advanced for any help, I really appreciate it. 非常感谢您的任何帮助,我非常感谢。

judging from this line in your error message: 从错误消息的这一行来看:

ActiveRecord::StatementInvalid (PG::UndefinedTable: ERROR: relation "users" does not exist ActiveRecord :: StatementInvalid(PG :: UndefinedTable:错误:关系“用户”不存在

it seems to me that the migrations did not run properly on Heroku. 在我看来,迁移在Heroku上无法正常运行。

i would try to run 我会试着跑

heroku rake db:reset ('heroku run rake db:reset' if you're on cedar) heroku rake db:reset(如果您在雪松上,则使用“ heroku run rake db:reset”)

heroku rake db:migrate ('heroku run rake db:migrate' if you're on cedar) heroku rake db:migrate(如果您在雪松上,则使用“ heroku run rake db:migrate”)

and see where that gets me. 看看哪里能带给我。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM