Heroku run rake db:migrate results in no change in the database, app restarted several times

rhjs picture rhjs · Apr 1, 2013 · Viewed 15.9k times · Source

I have a problem with pushing my migrations to the production database.

The issue:

  1. I've altered database schema by adding 1 column.
  2. I've migrated it to the production database:

    MacBook-Air-Mac:app msc$ rake db:migrate RAILS_ENV="production" [RailsAdmin] RailsAdmin initialization disabled by default. Pass SKIP_RAILS_ADMIN_INITIALIZER=false if you need it. == AddLengthColumnToBooks: migrating ========================================= -- add_column(:books, :length, :integer) -> 0.0017s == AddLengthColumnToBooks: migrated (0.0019s) ================================

  3. Thinking that the new DB schema is now in production, I've deployed the code which does some things with :length.

  4. In production, I got the following error:

    undefined method `length=' for #

  5. I did heroku rollback and downgraded the app to the latest reliable version.

  6. THEN (a bit too late probably) I found out that I have to heroku restart the app to load the new indexes. I did this several times.

  7. I opened the console then and checked Book.column_names, but there was no length

  8. I did heroku run rake db:migrate followed by heroku restart one more time, no change.

  9. I've tried migrating another column to the production db, but didn't get any message at all, not even the one from p.2.

What am I doing wrong here?

Update

Based on the answers of Philipe, I did a number of additional steps:

  1. git add db/schema.rb, git add db/migrate/20130325103953_add_length_column_to_books.rb and 'git add db/migrate/20130401041910_add_duration_column_to_books.rb'. Git's answer was:
  2. Changes to be committed: (use "git reset HEAD ..." to unstage)

    new file: db/migrate/20130325103953_add_length_column_to_books.rb new file: db/migrate/20130401041910_add_duration_column_to_books.rb modified: db/schema.rb

  3. Then I did git commit -m "Updating the schema".

  4. Again the output was:

     3 files changed, 168 insertions(+), 156 deletions(-)
    

    create mode 100644 db/migrate/20130325103953_add_length_column_to_books.rb create mode 100644 db/migrate/20130401041910_add_duration_column_to_books.rb

  5. Then I run heroku run rake db:migrate. Unfortunately there was no sign of migrations, simply got:

    Running rake db:migrate attached to terminal... up, run.5428 and that's it.

  6. In the production Rails Console, running Book.column_names still lacks both length and duration.

Now I'm even more out of ideas. `

Answer

John Beynon picture John Beynon · Apr 1, 2013

It doesn't look like you are pushing changes to Heroku. Steps should be as follows;

  1. Make changes to local code
  2. Run any migrations LOCALLY
  3. Add all changed files to Git git add .
  4. Commit all added files to git git commit -m "Adding features"
  5. Push the changes to Heroku git push heroku master - assuming you are using heroku as your remote name and you are working in the master branch
  6. If you have migrations run heroku run rake db:migrate to run the migrations ON HEROKU
  7. Following migrations do heroku restart

That should be all you need to get you working.