2017-01-07 116 views
0

我一直在讓我的應用程序準備好生產,而我正在努力耙取我的數據庫。它給我這個錯誤:PG :: UndefinedTable錯誤ruby on rails 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" 

知道是否還有其他東西需要解決我遇到的問題。謝謝:d

回答

1

看着你rake db:migrate:status你有一個問題,那就是一個移民Add code to events後應Create events遷移,因爲你是在event進行更改,但被後來創建了該表。所以,你應該解決這個問題,併爲臨時的解決辦法是你可以做的是:

rake db:migrate:up VERSION=20161219214142 

20161219214142Create Events在遷移的版本,所以這將運行特定遷移爲您和創建events表,然後,如果你願意運行rake db:migrate然後它會正常工作。

+0

那麼我該如何去改變這兩個的順序呢? – Aaron

+0

@Aaron這可能會幫助您http://stackoverflow.com/questions/10456761/rails-migration-change-sequence-or-order更改遷移順序。同時你可以嘗試臨時修復。 – Deep

+0

就像一個魅力,我現在可以看到我的生產applicaiton – Aaron

相關問題