How do I migrate my heroku database?

13,831

Solution 1

If you had a working database, you could recreate your tables from the schema:

heroku run rake db:schema:load

If you want to just reset the database to empty:

heroku run rake db:create

What is the error it is giving you? It might be more helpful to try to solve that problem rather than wipe everything.

Solution 2

This should be updated as heroku rake has been deprecated. Use heroku run rake now. See below, per command-line/stderr output, as of today (March 8, 2013):


Incorrect:

  • PROMPT>heroku rake db:migrate --app myApp

    WARNING: 'heroku rake'` has been deprecated. Please use 'heroku run rake' instead.


Correct:

  • PROMPT>heroku run rake db:migrate --app myApp

    Running rake db:migrate attached to terminal... up, run.2810

Solution 3

Try:

 heroku rake db:migrate VERSION=0

This will get your database to its starting point.

Solution 4

You can make heroku run directly into Heroku webapp

heroku command

and then heroku run rails db:migrate

heroku run rails db:migrate

Share:
13,831
BasicObject
Author by

BasicObject

Updated on June 09, 2022

Comments

  • BasicObject
    BasicObject almost 2 years

    I've tried:

    heroku rake db:migrate

    and

    heroku pg:push

    The first gives me a PGerror / rake aborted error.

    Is there a way to completely rebuild/reset my database with heroku? I can't seem to find it in their documentation.

    EDIT: I had a working database before this, but my tables and relationships have changed.

  • BasicObject
    BasicObject almost 13 years
    Looks like heroku rake db:migrate VERSION=0 then heroku rake db:create allowed me to recreate the database. Thank you @oded-harth and @felix
  • Nick
    Nick over 11 years
    heroku rake has been deprecated in favor of heroku run rake. At least, that's what the error message told me.
  • tomloprod
    tomloprod over 9 years
    Explain your code, please. The code itself does not say much.