Heroku run rake db:migrate results in no change in the database, app restarted several times
Solution 1
It doesn't look like you are pushing changes to Heroku. Steps should be as follows;
- Make changes to local code
- Run any migrations LOCALLY
- Add all changed files to Git
git add .
- Commit all added files to git
git commit -m "Adding features"
- Push the changes to Heroku
git push heroku master
- assuming you are usingheroku
as your remote name and you are working in themaster
branch - If you have migrations run
heroku run rake db:migrate
to run the migrations ON HEROKU - Following migrations do
heroku restart
That should be all you need to get you working.
Solution 2
I had the same problem; I git added the migrations, git pushed them to the server, cap deployed them, and the database didn't change. Logged in to the server directly, ran rake db:migrate, and the command line seemed to run the migration, but nothing changed.
In my case, somehow rake db:migrate was using the wrong RAILS_ENV. I logged in to the server, and ran
rake db:migrate RAILS_ENV=production
This caused the database to create the new columns, and then all of the code that I had debugged in the test database started working on the server.
Solution 3
I just had same problem. After adding a column to my DB locally, I did heroku run rake db:migrate -app [my app name]
. Running my code on production, I got ActiveRecord::UnknownAttributeError (unknown attribute '_____' for [table name].)
This solved my problem:
heroku restart --app [my app name]
Related videos on Youtube
rhjs
Updated on September 15, 2022Comments
-
rhjs over 1 year
I have a problem with pushing my migrations to the production database.
The issue:
- I've altered database schema by adding 1 column.
-
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) ================================
Thinking that the new DB schema is now in production, I've deployed the code which does some things with
:length
.-
In production, I got the following error:
undefined method `length=' for #
I did
heroku rollback
and downgraded the app to the latest reliable version.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.I opened the console then and checked
Book.column_names
, but there was nolength
I did
heroku run rake db:migrate
followed byheroku restart
one more time, no change.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:
-
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: -
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
Then I did
git commit -m "Updating the schema"
.-
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
-
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. In the production Rails Console, running
Book.column_names
still lacks both length and duration.
Now I'm even more out of ideas. `
-
Dave Munger about 9 yearsI have the same problem, however I took all of the steps you list and Heroku still ignores the migration completely.
-
Jack over 7 yearsI have in the past done migrations on Heroku without needing to restart, but for some reason this time it didn't work. Restarting after the migration fixed the issue.
-
dani24 about 2 years
heroku restart
was what I was missing. Thank u!