我只是在铁轨上学习红宝石。我创建了两个数据库表:trainers和tokimons。在本地主机(包括数据库)上一切正常,但在heroku上出现了问题。
这是日志:
2016-10-13T21:51:16.840425+00:00 heroku[router]: at=info method=GET path="/" host=a2-tokimon.herokuapp.com request_id=2f86b075-8d64-4616-984a-304df86d9768 fwd="142.58.35.51" dyno=web.1 connect=2ms service=11ms status=500 bytes=1669
2016-10-13T21:51:16.851541+00:00 app[web.1]: Started GET "/" for 142.58.35.51 at 2016-10-13 21:51:16 +0000
2016-10-13T21:51:16.854395+00:00 app[web.1]: Processing by WelcomeController#index as HTML
2016-10-13T21:51:16.858208+00:00 app[web.1]: Rendered welcome/index.erb within layouts/application (3.1ms)
2016-10-13T21:51:16.858340+00:00 app[web.1]: Completed 500 Internal Server Error in 4ms (ActiveRecord: 2.3ms)
2016-10-13T21:51:16.859867+00:00 app[web.1]:
2016-10-13T21:51:16.859872+00:00 app[web.1]: ActionView::Template::Error (PG::UndefinedTable: ERROR: relation "trainers" does not exist
2016-10-13T21:51:16.859873+00:00 app[web.1]: LINE 1: SELECT "trainers".* FROM "trainers"
2016-10-13T21:51:16.859874+00:00 app[web.1]: ^
2016-10-13T21:51:16.859874+00:00 app[web.1]: : SELECT "trainers".* FROM "trainers"):
2016-10-13T21:51:16.859875+00:00 app[web.1]: 51:
2016-10-13T21:51:16.859876+00:00 app[web.1]: 52:
2016-10-13T21:51:16.859877+00:00 app[web.1]: 53: <tbody>
2016-10-13T21:51:16.859877+00:00 app[web.1]: 54: <% @trainer.each do |trainer| %>
2016-10-13T21:51:16.859878+00:00 app[web.1]: 55: <tr class="<%= cycle('oddline', 'evenline') %>">
2016-10-13T21:51:16.859879+00:00 app[web.1]: 56: <td><%= trainer.pname %></td>
2016-10-13T21:51:16.859880+00:00 app[web.1]: 57: <td><%= trainer.level %></td>
2016-10-13T21:51:16.859881+00:00 app[web.1]: app/views/welcome/index.erb:54:in `_app_views_welcome_index_erb__3990380873615253162_69847032979680'
2016-10-13T21:51:16.859882+00:00 app[web.1]:
2016-10-13T21:51:16.859882+00:00 app[web.1]:
以下是trainers_controller.rb的一部分
class TrainersController < ApplicationController
before_action :set_trainer, only: [:show, :edit, :update, :destroy]
# GET /trainers
# GET /trainers.json
def index
@trainer = Trainer.all
end
以下是welcome_controller.rb的一部分
class WelcomeController < ApplicationController
# GET /welcome
def index
@trainer = Trainer.all
end
end
答案 0 :(得分:0)
行:
2016-10-13T21:51:16.859872+00:00 app[web.1]: ActionView::Template::Error (PG::UndefinedTable: ERROR: relation "trainers" does not exist
应该暗示你有postgres问题。特别是表格未定义。
假设你安装了heroku-cli,你需要在控制台中运行heroku run rake db:migrate
,这将执行Heroku所需的迁移。
以下是如何在Heroku上运行Rails(4)应用程序的文档:
https://devcenter.heroku.com/articles/getting-started-with-rails4
具体来说,这是关于迁移的部分:
https://devcenter.heroku.com/articles/getting-started-with-rails4#migrate-your-database
Heroku CLI文档和安装说明:
答案 1 :(得分:0)
PG::UndefinedTable
和PG::UndefinedColumn
错误是因为您尚未针对生产数据库运行迁移。
您应养成每次部署后运行heroku run rake:db:migrate
的习惯。