Heroku: How to update column name in heroku app - ruby-on-rails

Although my app works in my cloud development environment (colud9), We're sorry, but something went wrong. is displayed when I access heroku's url.
I changed column's name in my development environment.
I tried the followings commands;
git commit -a -m "xxx"
git push heroku master
heroku run rake db:migrate
heroku restart
When I check the schema in heroku, column's name haven't been changed.
How can I update column's name in my heroku app?
It could be appreciated if you could give me any suggestion.

I suspect that, you have not added the migration file before creating commit. so you need to add the migration file and then need to create commit. Please follow the following commands.
1) Add Migration files to Git git add .
2) Commit git commit -m "Adding migration file"
3) 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
4)run heroku run rake db:migrate to run the migrations ON HEROKU
5)Following migrations do heroku restar

What you could do is launch a console on heroku:
heroku run console
For e.g you want to update column name for users table
Then do the following:
User.all.each {|user| user.update_attribute :column_name}
In case you want to give some default value to your column, than do the following:
User.all.each {|user| user.update_attribute :column_name, 'value'}
Hope it helps.

run heroku run rake db:version check if the version matches your last migration in your local machine. if not follow #power suggestion.

Related

Database entry not showing up on Heroku

I am developing my first Rails app, and I have made some database entries that are showing up in the development environment, but not in the production environment (Heroku). I have run
git add
git commit
git push origin master
git push heroku master
rake db:migrate
in the terminal.
$ heroku create
$ git push heroku master
After running these commands, to get the application’s database to work, you’ll also have to migrate the production database:
$ heroku run rake db:migrate
$ heroku open
if this doesn't work please show your logs.
you just need to run
heroku run rake db:migrate

Heroku running old version of seed file

I am having an odd Heroku problem. I successfully pushed to Heroku with a new seed file and I saw the changes go through, and this seed file just has one Item.create in it. The old seed file has 10000 creates in it. The seeding should be very quick. So far, I:
1) Made sure that I pushed from master to heroku master. I ran git push heroku master from master
2) I made sure to git add and git commit.
3) When I run heroku run rake db:seed, it still runs like this 100000 line seed file. Any ideas on what might be going on?
Did you reset the database in heroku before updating the seed file? If not, run
$ heroku pg:reset DATABASE
$ heroku run rake db:migrate
$ heroku run rake db:seed
This removes the previous seed from the production database first.

Rails rake db:rollback on Heroku not working. Now I can't add any new migrations

I have an app that is working fine locally. At one point I tried installed the Act As Taggable gem, which generated a series of migration files. Now I rolled back locally after we voted against using that gem - but after deploying to heroku, it looks like 5 of these migration files did upload to heroku.
I then ran
`heroku run rake db:migrate'
I am now receiving this error
'uninitialized constant AddTaggingsCounterCacheToTags::ActsAsTaggableOn/app/db/migrate/20141107010718_add_taggings_counter_cache_to_tags.acts_as_taggable_on_engine.rb:6:in `up'
Now I don't need the "AddTaggingsCounterCacheToTags" but I definitely need a migration that was supposed to run after this.
Any tips on how I can remove this from the production/heroku server? How I can remove only specific migrations and keep the newest migration I made?
Thanks!
Okay folks. I got it.
The problem was that after I removed the files locally, they were still present on git. The process was to remove the migration that was causing the error and then I could have all migrations after come through just fine. Commands are below...
git rm [filename]
git commit -a -m "removed the migrations causing the error from git too"
git push origin master
git push heroku master
heroku run rake db:migrate
There is an issue with having an empty/unnecessary table in the database now, but the important thing is - I can continue to add migrations and my newest features are now working properly on production!
Cheers!

Deploying Heroku app--updating my code?

This is a basic, stupid question, but I configured my Rails app to deploy on Heroku, and I'm able to open the application from my Heroku account, etc. But when I want to change my code, do I need to re-deploy the whole application? I tried just committing/pushing to heroku master, but I get the error "fatal: remote end hung up unexpectedly." What should I do instead?
Also: am I supposed to run db:migrate BEFORE deploying/pushing?
There is nothing stupid about a basic question, as everyone has to start somewhere.
The basic process with deploying a Rails app to Heroku is to:
Make changes
Add and Commit your changes ($ git add files_changed.rb & $ git commit -m "make changes")
Push your changes to Heroku ($ git push heroku master)
This then pushes your code to the remote Heroku repository and redeploys your Rails application. If you have made any database migrations, you need to run:
$ heroku run rake db:migrate
This runs db:migrate on your heroku app - see how that works? :)
Running rake db:migrate locally simply migrates your local development database.

Heroku and Rails: transferring db to staging and db:migrate

I've been working on a Heroku app for several months. We've recently set up a staging server and occasionally sync the staging db with the production db. The three main commands in use are:
$ heroku pgbackups:capture --app myapp
$ heroku pg:reset DATABASE --app myapp-staging --confirm myapp-staging"
$ heroku pgbackups:restore DATABASE `heroku pgbackups:url --app myapp` --app myapp-staging
The problem is that after running the third command, I need to run heroku run rake db:migrate --app myapp-staging. We have a few dozen migrations now, including some that refer to Ruby classes that we've deleted or renamed.
This causes the migrations to fail to fully run. What's the solution here? Should I delete the old migrations that fail and commit these changes to the git repo?
Re-running this script fixed the error, so it seems like the schema should just copy over. For anyone seeing a failing migration like I did, the pgbackups:restore command probably failed for you, so re-run that.
You can also checkout the transfer command now as part of pgbackups .. see this post
How do I transfer production database to staging on Heroku using pgbackups? Getting error

Resources