我是使用Rails和Heroku的新手,并且一直在努力推动一款在本地工作得很好的应用。我可以把它推到heroku(貌似),但当我试图查看它时,我得到了
ActionView::Template::Error (PG::UndefinedTable: ERROR: relation "users" does not exist
我从挖掘类似的SO帖子,我认为它与应用程序在heroku中使用的数据库有关,但到目前为止使用heroku run rake db:reset
然后heroku run rake db:migrate
返回了完全相同的错误。我确定我在这里做了一些非常误导的事情,但我希望有人可以帮我搞清楚。这是我heroku logs
所得到的:
2017-01-26T05:24:34.232181+00:00 app[web.1]: I, [2017-01-26T05:24:34.232138 #4] INFO -- : [7baf7e95-1518-4773-9f3c-39aef34651f2] Completed 500 Internal Server Error in 7ms (ActiveRecord: 1.8ms)
2017-01-26T05:24:34.233452+00:00 app[web.1]: F, [2017-01-26T05:24:34.233406 #4] FATAL -- : [7baf7e95-1518-4773-9f3c-39aef34651f2]
2017-01-26T05:24:34.233498+00:00 app[web.1]: F, [2017-01-26T05:24:34.233455 #4] FATAL -- : [7baf7e95-1518-4773-9f3c-39aef34651f2] ActionView::Template::Error (PG::UndefinedTable: ERROR: relation "users" does not exist
2017-01-26T05:24:34.233500+00:00 app[web.1]: LINE 1: SELECT "users".* FROM "users" WHERE "users"."id" IS NULL LI...
2017-01-26T05:24:34.233501+00:00 app[web.1]: ^
2017-01-26T05:24:34.233501+00:00 app[web.1]: : SELECT "users".* FROM "users" WHERE "users"."id" IS NULL LIMIT $1):
2017-01-26T05:24:34.233649+00:00 app[web.1]: [7baf7e95-1518-4773-9f3c-39aef34651f2] 21: <div class="container">
2017-01-26T05:24:34.233648+00:00 app[web.1]: F, [2017-01-26T05:24:34.233606 #4] FATAL -- : [7baf7e95-1518-4773-9f3c-39aef34651f2] 20: <div class="header">
2017-01-26T05:24:34.233650+00:00 app[web.1]: [7baf7e95-1518-4773-9f3c-39aef34651f2] 22: <a href="../messages"><h1 class="logo">MessagesApp</h1> <img class="logo-img" src="http://vignette2.wikia.nocookie.net/titanfall/images/3/3a/Icon_Chat.png/revision/latest?cb=20140504182858"></a>
2017-01-26T05:24:34.233650+00:00 app[web.1]: [7baf7e95-1518-4773-9f3c-39aef34651f2] 23: <% if logged_in? %>
2017-01-26T05:24:34.233651+00:00 app[web.1]: [7baf7e95-1518-4773-9f3c-39aef34651f2] 24: <%= link_to "Log out".html_safe, logout_path, method: "delete", class: "login-btn btn btn-default navbar-btn" %>
2017-01-26T05:24:34.233652+00:00 app[web.1]: [7baf7e95-1518-4773-9f3c-39aef34651f2] 25: <% else %>
2017-01-26T05:24:34.233652+00:00 app[web.1]: [7baf7e95-1518-4773-9f3c-39aef34651f2] 26: <%= link_to "Log in".html_safe, login_path, class: "login-btn btn btn-default navbar-btn" %>
2017-01-26T05:24:34.233692+00:00 app[web.1]: F, [2017-01-26T05:24:34.233648 #4] FATAL -- : [7baf7e95-1518-4773-9f3c-39aef34651f2]
2017-01-26T05:24:34.233718+00:00 app[web.1]: F, [2017-01-26T05:24:34.233685 #4] FATAL -- : [7baf7e95-1518-4773-9f3c-39aef34651f2] app/helpers/sessions_helper.rb:7:in `current_user'
2017-01-26T05:24:34.233718+00:00 app[web.1]: [7baf7e95-1518-4773-9f3c-39aef34651f2] app/helpers/sessions_helper.rb:11:in `logged_in?'
2017-01-26T05:24:34.233719+00:00 app[web.1]: [7baf7e95-1518-4773-9f3c-39aef34651f2] app/views/layouts/application.html.erb:23:in `_app_views_layouts_application_html_erb__1527317900822670125_70088753231660'
2017-01-26T05:24:34.240424+00:00 heroku[router]: at=info method=GET path="/" host=nameless-bayou-71899.herokuapp.com request_id=7baf7e95-1518-4773-9f3c-39aef34651f2 fwd="207.67.119.130" dyno=web.1 connect=1ms service=12ms status=500 bytes=1733
这是我认为相关的代码:
<% @messages.each do |message| %>
<div class="message <%= 'right' if logged_in? && message.user_id==current_user.id %>">
<% if message.user_id==current_user.id %>
<%= '<p class="user_name text-right">Me</p>'.html_safe %>
<% else %>
<p class="user_name"><%= message.user.name %></p>
<% end %>
<p class="content"><%= message.content %></p>
<p class="time <%= 'right' if message.user_id==current_user.id %>"><%= time_ago_in_words(message.created_at) %><br>
<% if message.user_id==current_user.id %>
<%= link_to 'Delete', message_path(message),
class: "delete-link",
method: :delete,
data: { confirm: 'Are you sure?' } %></p>
<% end %>
</div>
<% end %>
答案 0 :(得分:0)
您可以尝试将迁移消息模型划分为两个单独的迁移。第一次迁移创建模型。第二次迁移增加了参考关系