Search code examples
ruby-on-railsrubyrakemigratepg

Rails 4 `rake db:migrate` in Heroku instances, references error


I'm trying to rake db:migrate my project in Heroku's servers but the rake process is trying to create an table targetings before ads where targetings has a relation with ads so the references error pops up, like:

PG::UndefinedTable: ERROR:  relation "ads" does not exist
: ALTER TABLE "targetings" ADD CONSTRAINT "fk_rails_dcece48daa"
FOREIGN KEY ("ad_id")
  REFERENCES "ads" ("id")

Can some one tell me how define an order or force the table ads being created before the others?


Solution

  • In heroku production environment
    First you have to set up database with this command

    heroku run rake db:setup