我正在尝试部署我在Rails 4 in action教程中制作的rails应用程序。我已经成功地推送到了heroku但是当运行rake db:migrate时我得到了这个错误:
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")
该应用程序在本地工作,表格确实存在 如果您需要任何其他文件发布,请告诉我。 一如既往地感谢您的帮助。
答案 0 :(得分:3)
我猜您以前的迁移工作正在丢失。您可以尝试执行以下步骤:
heroku run rake db:create
heroku run rake db:schema:load
heroku run rake db:migrate
答案 1 :(得分: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
你应该被设定。