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.
Related
Currently on Ch 2 of Hartl's tutorial in which I make a simple app with users and microposts.
I add a few users and microposts to the database.
Near the end of the chapter, it gets you to deploy the app to Heroku. When I view the app on Heroku however, there are no users or microposts anymore.
How do I get the existing data to be deployed as well?
Heroku has different database than your app locally. So every data you created in the local app will not be pushed to Heroku when you run git push heroku master
I would create a database dump (maybe the Seed Dump is interesting) so you can import this in Heroku or you could place the users and microposts in a seed file and run heroku run rake db:seed
http://railscasts.com/episodes/179-seed-data gives an brief explanation on how you could seed the db
Use YamlDb gem to dump data to a yaml file.
Create data dump by:
rake db:data:dump -> Dump contents of Rails database to db/data.yml
Push code to Heroku:
git push heroku master
Load data to heroku database:
heroku run rake db:data:load -> Load contents of db/data.yml into the database
If you're using postgres you can push your local database to your heroku app doing the following:
Checkout your config/database.yml file to see what the development database is named. For this example I'll call it cool_development. Then once you have run:
git push heroku master
Then run the migrations to create the database: heroku run rake db:migrate
Then push your database to heroku: heroku pg:push cool_development DATABASE_URL --app app_name_here
The database heroku creates for you is accessed using the DATABASE_URL environment variable so you don't need to change anything in the above line except for the local database name unless your app is named 'cool' lol.
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
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!
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.
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