2016-12-01 188 views
1

我想部署我的rails應用程序,我在動作教程中遵循Rails 4。我已經成功地推到Heroku的,但是當運行耙分貝:遷移我得到這個錯誤:PG :: Undefinedtable:錯誤:當運行rake db:在Heroku上遷移

heroku run rake db:migrate 
Running rake db:migrate on ⬢ fast-lowlands-66439... up, run.6711 (Free) 
    ActiveRecord::SchemaMigration Load (10.5ms) SELECT "schema_migrations".* FROM "schema_migrations" 
Migrating to CreateStates (20161123222713) 
    (2.5ms) BEGIN 
== 20161123222713 CreateStates: migrating ===================================== 
-- create_table(:states) 
-- add_reference(:tickets, :state, {:index=>true, :foreign_key=>true}) 
    (1.4ms) ALTER TABLE "tickets" ADD "state_id" integer 
    (9.7ms) CREATE INDEX "index_tickets_on_state_id" ON "tickets" ("state_id") 
    (4.6ms) ALTER TABLE "tickets" ADD CONSTRAINT "fk_rails_fc553dc329" 
FOREIGN KEY ("state_id") 
    REFERENCES "states" ("id") 

    (0.6ms) ROLLBACK 
rake aborted! 
StandardError: An error has occurred, this and all later migrations canceled: 

PG::UndefinedTable: ERROR: relation "states" does not exist 
: ALTER TABLE "tickets" ADD CONSTRAINT "fk_rails_fc553dc329" 
FOREIGN KEY ("state_id") 
    REFERENCES "states" ("id") 

的應用本地工作和表確實存在。
讓我知道你是否需要任何額外的文件發佈。 非常感謝您的幫助。

回答

2

我在Heroku上刪除該數據庫並重新創建它(你將失去保存到數據庫中的所有數據):

heroku pg:reset DATABASE_URL --confirm your_app_name 

與替換your_app_name在heroku上的應用程序名稱,但保持原樣DATABASE_URL。

然後運行:

heroku run rake db:setup 

它將運行這兩個命令:

heroku run rake db:migrate 
    heroku run rake db:seed 

而且你應該設置。

2

我想你以前的遷移是缺失的。你可以嘗試這樣做,因爲下面的步驟:

heroku run rake db:create 
heroku run rake db:schema:load 
heroku run rake db:migrate 
相關問題