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

use*_*293 2 database ruby-on-rails heroku ruby-on-rails-4

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

heroku open
Run Code Online (Sandbox Code Playgroud)

我的浏览器出现以下错误

We're sorry, but something went wrong.

If you are the application owner check the logs for more information.
Run Code Online (Sandbox Code Playgroud)

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

[36m2014-04-28T08:22:01.921791+00:00 app[web.1]:?[0m PG::UndefinedTable: ERROR:
 relation "premails" does not exist
Run Code Online (Sandbox Code Playgroud)

那是什么意思?我有以下迁移:

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

        t.text :email

      t.timestamps
    end
  end
end
Run Code Online (Sandbox Code Playgroud)

和型号:

class Premail < ActiveRecord::Base

end
Run Code Online (Sandbox Code Playgroud)

如何在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
Run Code Online (Sandbox Code Playgroud)

由于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
Run Code Online (Sandbox Code Playgroud)

我在Windows8 64上

谢谢!

Ric*_*eck 6

几个问题:

  1. 您没有设置"真实"的生产数据库
  2. 你没有rake db:migrate在生产中使用过

首先,您需要创建一个在Heroku上运行的生产数据库.Heroku不会为您托管任何数据库 - 它只能在Amazon EC2堆栈上运行; 意味着您必须生成自己的数据库服务器,或使用Heroku的postgres实例之一

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