PG :: UndefinedTable ERROR ruby​​ on rails heroku

时间:2017-01-07 07:07:41

标签: ruby-on-rails postgresql heroku

我一直在准备我的应用程序进行生产,我正在努力耙我的数据库。它给了我这个错误:

PG::UndefinedTable: ERROR: relation "events" does not exist
: ALTER TABLE "events" ADD "code" character varying

这是我的database.yml文件:

# SQLite version 3.x
#   gem install sqlite3
#
#   Ensure the SQLite 3 gem is defined in your Gemfile
#   gem 'sqlite3'
#
default: &default
  adapter: postgresql
  pool: 5
  timeout: 5000

development:
  <<: *default
  database: db/development.sqlite3

production:
  <<: *default
  database: db/production.postgresql

这是我的事件迁移文件:

class CreateEvents < ActiveRecord::Migration[5.0]
  def change
    create_table :events do |t|
      t.string :name
      t.string :partycode
      t.references :user, foreign_key: true

      t.timestamps
    end
  end
end

修改 当我运行rake db:migrate:status时,我得到以下结果: enter image description here 最后,这是我的gemfile:

source 'http://rubygems.org'

    gem 'bootstrap-sass', '3.2.0.2'

    gem 'bcrypt',         '3.1.11'

    gem 'will_paginate'

    gem 'responders'

    gem 'rails', '~> 5.0.0', '>= 5.0.0.1'

    gem 'puma', '~> 3.0'

    gem 'sass-rails', '~> 5.0'

    gem 'uglifier', '>= 1.3.0'

    gem 'coffee-rails', '~> 4.2'

    gem "heroku"

    gem 'coffee-script-source', '1.8.0'

    gem 'jquery-rails'

    gem 'turbolinks', '~> 5'

    gem 'jbuilder', '~> 2.5'


    group :development, :test do
      # Call 'byebug' anywhere in the code to stop execution and get a debugger console
      gem 'sqlite3'
      gem 'byebug', platform: :mri
    end

    group :production do
      gem 'web-console'
      gem 'pg'
    end

    gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
    ruby "2.2.4"

Lemme知道你还有什么需要解决我遇到的这个问题。谢谢:D

1 个答案:

答案 0 :(得分:1)

看到您的rake db:migrate:status有一个问题是迁移Add code to events,应该在Create events迁移之后,因为您正在event进行更改,但表格正在进行中之后创建。所以你应该解决这个问题,暂时解决你可以做的事情:

rake db:migrate:up VERSION=20161219214142

20161219214142是您Create Events迁移的版本,因此这将为您运行特定的迁移并创建events表,然后运行rake db:migrate然后它会很好。