Search code examples
ruby-on-railsgitherokudatabase-migrationmigrate

Heroku run rake db:migrate command doesn't update database


I'm reading railstutorial.org Chapter 2 (about toy_app) using cloud IDE and I've run into a problem. I'm newbie so I would appreciate a simple sollution and explanation what I did wrong.

  1. I followed every step as described in tutorial: I created my 'hello world' index page and I pushed it to heroku. I renamed my heroku site as well (it wasn't required in tutorial). Everything was fine at that moment.
  2. I added user and micropost models. I've started a local server (on second terminal by typing rails server -b $IP -p $PORT) and added some users and microposts. Again, everything was working as expected.
  3. I didn't close local server. I committed changes to git and I pushed it to Bitbucket and then to heroku. Finally, I typed heroku run rake db:migrate. It was the final step of this tutorial.

Everything seemed to be Ok, but I noticed that posts and users I added on local server weren't visible on my heroku site. Since I didn't close my local server, I checked it and posts I created were still available. As I said, situation on my heroku site was different.

I didn't get any errors during that process, only one warning after typing git push: Warning: Permanently added the RSA host key for IP address ... to the list of known hosts. Next time it didn't show up.

After my first try of every step I got promising outputs. After second and next tries it returned

On branch master
Your branch is up-to-date with 'origin/master'.

nothing to commit, working directory clean`

and

Everything up-to-date

So still nothing worrying.

I tried to restart server, to follow those steps again after closing my local server but it didn't help. I searched for solution but only what I found were problems with massive errors or different problems.

Actually, It is problem I can go along with because I don't need it updated at this stage, but I would like to hear an answer and find out if there is something wrong with heroku or it it normal behavior or even if it is newbie's blindness.


Solution

  • First your local database and heroku database are different. Any user created on local app won't be available on heroku app unless you use a common database.

    rake db:migrate, in its most basic form, just runs the change or up method for all the migrations that have not yet been run. If there are no such migrations, it exits. It will run these migrations in order based on the date of the migration.

    Try creating user and post on heroku app, it should work all fine.