部署到Heroku(表不存在错误)

时间:2014-04-28 08:31:34

标签: ruby-on-rails database heroku ruby-on-rails-4

我正在构建一个示例预注册页面,人们可以在应用程序启动前注册他们的电子邮件。当我输入时:

heroku open

我的浏览器出现以下错误

We're sorry, but something went wrong.

If you are the application owner check the logs for more information.

检查我的日志后,我发现了这个奇怪的错误:

[36m2014-04-28T08:22:01.921791+00:00 app[web.1]:←[0m PG::UndefinedTable: ERROR:
 relation "premails" does not exist
这是什么意思?我有以下迁移:

class CreatePremails < ActiveRecord::Migration
  def change
    create_table :premails do |t|

        t.text :email

      t.timestamps
    end
  end
end

和型号:

class Premail < ActiveRecord::Base

end

如何在Heroku上部署它需要做什么?我不确定这是不是问题,或者我是否需要更改我的database.yml文件。目前我在那里有这个:

# SQLite version 3.x
#   gem install sqlite3
#
#   Ensure the SQLite 3 gem is defined in your Gemfile
#   gem 'sqlite3'
development:
  adapter: sqlite3
  database: db/development.sqlite3
  pool: 5
  timeout: 5000

# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
  adapter: sqlite3
  database: db/test.sqlite3
  pool: 5
  timeout: 5000

production:
  adapter: sqlite3
  database: db/production.sqlite3
  pool: 5
  timeout: 5000

由于Heroku只适用于pg,我可能需要在那里进行更改吗?

一些额外的信息,这是我的Gemfile:

source 'https://rubygems.org'


gem 'pg'

gem 'bootstrap-sass', '~> 3.1.1'

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.0.3'

# Use SCSS for stylesheets
gem 'sass-rails', '~> 4.0.0'

# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'

# Use CoffeeScript for .js.coffee assets and views
gem 'coffee-rails', '~> 4.0.0'

# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby

# Use jquery as the JavaScript library
gem 'jquery-rails'

# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'

# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 1.2'

group :doc do
  # bundle exec rake doc:rails generates the API under doc/api.
  gem 'sdoc', require: false
end

group :production do
  gem 'rails_12factor', '0.0.2'
end

我在Windows8 64上

谢谢!

1 个答案:

答案 0 :(得分:6)

几个问题:

  
      
  1. 您尚未设置“真实”的生产数据库
  2.   
  3. 您尚未在生产中使用rake db:migrate
  4.   

首先,您需要create a production db to run on Heroku。 Heroku不会为您托管任何数据库 - 它只能在Amazon EC2堆栈上运行;意味着您必须生成自己的数据库服务器,或使用Heroku的postgres实例之一

拥有生产数据库后,您只需要从命令行运行heroku run rake db:migrate即可在数据库服务器上填充所有表,这应该可以解决错误