无法在Heroku上部署基本的Rails应用程序

3

首先,我对Ruby on Rails是个新手,如果问题看起来很愚蠢,请见谅。

我正在跟随一个关于Heroku和Rails应用的教程,当我运行git push heroku master并查看实际网站时,我收到以下消息: 抱歉,出了点问题。如果您是应用程序所有者,请检查日志以获取更多信息。

当我在控制台中运行heroku logs时,我得到以下结果:

2018-05-20T03:33:23.748800+00:00 app[api]: Enable Logplex by user xxx.romain@gmail.com
2018-05-20T03:33:23.554110+00:00 app[api]: Release v1 created by user xxx.romain@gmail.com
2018-05-20T03:33:23.748800+00:00 app[api]: Release v2 created by user xxx.romain@gmail.com
2018-05-20T03:33:23.554110+00:00 app[api]: Initial release by user xxx.romain@gmail.com
2018-05-20T03:33:46.000000+00:00 app[api]: Build started by user xxx.romain@gmail.com
2018-05-20T03:34:29.457658+00:00 app[api]: Set LANG, RACK_ENV, RAILS_ENV, RAILS_LOG_TO_STDOUT, RAILS_SERVE_STATIC_FILES, SECRET_KEY_BASE config vars by user xxx.romain@gmail.com
2018-05-20T03:34:29.457658+00:00 app[api]: Release v3 created by user xxx.romain@gmail.com
2018-05-20T03:34:30.828730+00:00 app[api]: Release v4 created by user xxx.romain@gmail.com
2018-05-20T03:34:30.828730+00:00 app[api]: Attach DATABASE (@ref:postgresql-tapered-27211) by user xxx.romain@gmail.com
2018-05-20T03:34:31.131189+00:00 app[api]: Scaled to console@0:Free rake@0:Free web@1:Free worker@0:Free by user xxx.romain@gmail.com
2018-05-20T03:34:31.115804+00:00 app[api]: Release v5 created by user xxx.romain@gmail.com
2018-05-20T03:34:31.115804+00:00 app[api]: Deploy 0248e11a by user xxx.romain@gmail.com
2018-05-20T03:34:31.000000+00:00 app[api]: Build succeeded
2018-05-20T03:34:36.168184+00:00 heroku[web.1]: Starting process with command `bin/rails server -p 57618 -e production`
2018-05-20T03:34:41.855283+00:00 app[web.1]: => Booting Puma
2018-05-20T03:34:41.855302+00:00 app[web.1]: => Rails 5.1.6 application starting in production
2018-05-20T03:34:41.855303+00:00 app[web.1]: => Run `rails server -h` for more startup options
2018-05-20T03:34:41.855305+00:00 app[web.1]: Puma starting in single mode...
2018-05-20T03:34:41.855313+00:00 app[web.1]: * Version 3.11.4 (ruby 2.3.4-p301), codename: Love Song
2018-05-20T03:34:41.855315+00:00 app[web.1]: * Min threads: 5, max threads: 5
2018-05-20T03:34:41.855316+00:00 app[web.1]: * Environment: production
2018-05-20T03:34:41.855503+00:00 app[web.1]: * Listening on tcp://0.0.0.0:57618
2018-05-20T03:34:41.855969+00:00 app[web.1]: Use Ctrl-C to stop
2018-05-20T03:34:42.411033+00:00 heroku[web.1]: State changed from starting to up
2018-05-20T03:34:43.450895+00:00 app[web.1]: [5a2cc1ab-9701-42e6-accc-2f372ff837f1] Started GET "/" for 27.32.8.50 at 2018-05-20 03:34:43 +0000
2018-05-20T03:34:43.487004+00:00 app[web.1]: [5a2cc1ab-9701-42e6-accc-2f372ff837f1]   Rendering keywords/index.html.erb within layouts/application
2018-05-20T03:34:43.463124+00:00 app[web.1]: [5a2cc1ab-9701-42e6-accc-2f372ff837f1] Processing by KeywordsController#index as HTML
2018-05-20T03:34:44.722888+00:00 heroku[router]: at=info method=GET path="/" host=tweetscoperm.herokuapp.com request_id=5a2cc1ab-9701-42e6-accc-2f372ff837f1 fwd="27.32.8.50" dyno=web.1 connect=1ms service=1278ms status=500 bytes=1827 protocol=https
2018-05-20T03:34:44.715829+00:00 app[web.1]: [5a2cc1ab-9701-42e6-accc-2f372ff837f1]   Keyword Load (2.3ms)  SELECT "keywords".* FROM "keywords"
2018-05-20T03:34:44.717471+00:00 app[web.1]: [5a2cc1ab-9701-42e6-accc-2f372ff837f1]   Rendered keywords/index.html.erb within layouts/application (1230.3ms)
2018-05-20T03:34:44.717773+00:00 app[web.1]: [5a2cc1ab-9701-42e6-accc-2f372ff837f1] Completed 500 Internal Server Error in 1254ms (ActiveRecord: 33.5ms)
2018-05-20T03:34:44.719239+00:00 app[web.1]: [5a2cc1ab-9701-42e6-accc-2f372ff837f1]
2018-05-20T03:34:44.720128+00:00 app[web.1]: [5a2cc1ab-9701-42e6-accc-2f372ff837f1] ActionView::Template::Error (PG::UndefinedTable: ERROR:  relation "keywords" does not exist
2018-05-20T03:34:44.720132+00:00 app[web.1]: ^
2018-05-20T03:34:44.720130+00:00 app[web.1]: LINE 1: SELECT "keywords".* FROM "keywords"
2018-05-20T03:34:44.720134+00:00 app[web.1]: : SELECT "keywords".* FROM "keywords"):
2018-05-20T03:34:44.720461+00:00 app[web.1]: [5a2cc1ab-9701-42e6-accc-2f372ff837f1]     11:   </thead>
2018-05-20T03:34:44.720464+00:00 app[web.1]: [5a2cc1ab-9701-42e6-accc-2f372ff837f1]     12:
2018-05-20T03:34:44.720466+00:00 app[web.1]: [5a2cc1ab-9701-42e6-accc-2f372ff837f1]     13:   <tbody>
2018-05-20T03:34:44.720468+00:00 app[web.1]: [5a2cc1ab-9701-42e6-accc-2f372ff837f1]     14:     <% @keywords.each do |keyword| %>
2018-05-20T03:34:44.720469+00:00 app[web.1]: [5a2cc1ab-9701-42e6-accc-2f372ff837f1]     15:       <tr>
2018-05-20T03:34:44.720471+00:00 app[web.1]: [5a2cc1ab-9701-42e6-accc-2f372ff837f1]     16:         <td><%= keyword.word %></td>
2018-05-20T03:34:44.720473+00:00 app[web.1]: [5a2cc1ab-9701-42e6-accc-2f372ff837f1]     17:         <td><%= link_to 'Show', keyword %></td>
2018-05-20T03:34:44.720531+00:00 app[web.1]: [5a2cc1ab-9701-42e6-accc-2f372ff837f1]
2018-05-20T03:34:44.720593+00:00 app[web.1]: [5a2cc1ab-9701-42e6-accc-2f372ff837f1] app/views/keywords/index.html.erb:14:in `_app_views_keywords_index_html_erb___2939922413078681924_23601960'
2018-05-20T03:34:45.523130+00:00 heroku[router]: at=info method=GET path="/favicon.ico" host=tweetscoperm.herokuapp.com request_id=ec46bf49-b91c-4bf2-b017-a15b4cef63a8 fwd="27.32.8.50" dyno=web.1 connect=1ms service=2ms status=200 bytes=143 protocol=https

看完这段内容,我没有找到任何可能引起问题的原因。

目前为止,我的database.yml文件如下所示:

development:
 adapter: postgresql
 database: tscope_dev
 pool: 5
 timeout: 5000

test:
 adapter: postgresql
 database: tscope_test
 pool: 5
 timeout: 5000

production:
 adapter: postgresql
 database: tscope_production
 pool: 5
 timeout: 5000

我的Gemfile:

source 'https://rubygems.org'

git_source(:github) do |repo_name|
  repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/")
  "https://github.com/#{repo_name}.git"
end


# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 5.1.6'
# Use sqlite3 as the database for Active Record
# gem 'sqlite3'

# Using PostgreSQL as DB
gem 'pg'

# Use Puma as the app server
gem 'puma', '~> 3.7'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# See https://github.com/rails/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby

# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.2'
# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
gem 'turbolinks', '~> 5'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.5'
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 4.0'
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'

# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development

gem 'rails_12factor', group: :production

group :development, :test do
  # Call 'byebug' anywhere in the code to stop execution and get a debugger console
  gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
  # Adds support for Capybara system testing and selenium driver
  gem 'capybara', '~> 2.13'
  gem 'selenium-webdriver'
end

group :development do
  # Access an IRB console on exception pages or by using <%= console %> anywhere in the code.
  gem 'web-console', '>= 3.3.0'
  gem 'listen', '>= 3.0.5', '< 3.2'
  # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
  gem 'spring'
  gem 'spring-watcher-listen', '~> 2.0.0'
end

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]

ruby '2.3.4'

我创建了数据库并进行了迁移,同时也运行了bundle install。这是一个最基本的应用程序,只生成了一个使用脚手架生成的控制器。
有人知道问题可能出在哪里吗?即使是最小的提示也会帮助我,因为我现在真的不知道要看什么。
如果您需要有关我的代码的任何其他信息,请随时询问。
提前感谢:)
编辑 通过在控制台中运行heroku run rake db:migrate解决了此问题。 结果是我没有在Heroku上运行迁移。

你在Heroku上运行了迁移吗?还是只在本地运行了?要在Heroku上运行,请从控制台运行 heroku run rake db:migrate - jvillian
我刚试了一下,得到的输出是: heroku run db:migrate Running db:create on ⬢ tweetscoperm... up, run.7410 (Free) bash: db:create: command not found仍然收到相同的错误消息... - Moromain
那真的解决了问题。出于某种原因,我实际上必须传递命令 heroku run RAKE db:migrate,但最终解决了它。非常感谢你的帮助 :) - Moromain
是的,我明白了。我的原始评论中确切地包含了 heroku run rake db:migrate,很高兴你搞定了。我将其添加为答案,这样你就可以为未来的 SO 搜索者点赞/接受答案了。 - jvillian
1个回答

1
这行内容:
ActionView::Template::Error (PG::UndefinedTable: ERROR:  relation "keywords" does not exist

提示您在Heroku上尚未运行迁移。

为此,请在控制台中执行以下操作:

heroku run rake db:migrate

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接