Heroku rake db:migrate doesn't work - ruby-on-rails-3

Ruby 1.9.2 Rails 3.1
After the day of fighting with heroku issues I was able to finally have the command 'git push heroku master to work properly'.
Gemfile has proper enties and pg gem is installed
group :production do
gem 'pg'
end
group :development, :test do
gem 'sqlite3'
end
At this point application has been uploaded and start page can be viewed here http://growing-day-7939.heroku.com/
The next step should be migrating the database to the heroku with 'heroku rake db:migrate"
and it always fails.
c:\RailsInstaller\work\rfclub>heroku rake db:migrate
No app specified.
Run this command from an app folder or specify which app to use with --app <app name>
Other heroku commands fail with the same error as above - heroku ps, heroku logs, heroku config.
I've tried deleting and recreating the app, even tried creating the new heroku account and repeating the steps, but nothing seems to help.
Any ideas would be appreciated, I'm really stuck.

I think you'll need to deploy Rails 3.1 apps on Heroku's Cedar stack, via heroku create --stack cedar. The migration command will be heroku run rake db:migrate.

Related

The PGconn, PGresult, and PGError constants are deprecated on Heroku and Rails

I reset the database on Heroku in the database setting and ran heroku run rake db:migrate. Although it created all the data tables with correct columns per local database, it does not migrate any existing local data. Heroku database is just empty. In the past I ran the above code and worked fine but this time got stuck as shown below:
mac-a:skiny ran$ heroku run bundle exec rake db:migrate
Running bundle exec rake db:migrate on ⬢ blooming-citadel-66205... up, run.3076 (Hobby)
The PGconn, PGresult, and PGError constants are deprecated, and will be
removed as of version 1.0.
You should use PG::Connection, PG::Result, and PG::Error instead, respectively.
Called from /app/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:240:in `load_dependency'
ActiveRecord::SchemaMigration Load (1.2ms) SELECT "schema_migrations".* FROM "schema_migrations"
As a note, I quit mac terminal while running heroku run rake db:reset and maybe there is some internal error...
Try to the following, edit your Gemfile like below
gem 'pg', '~> 0.20.0'
Or
gem 'pg', '~> 0.11'
Then bundle install and try, it's working on my hand.
Note: the tilde sign before the >, that's not a dash
Once you make this update in your group production of your Gemfile, ensure you run bundle install --without production (to update Gemfile.lock file), do a git add/commit cycle, then re-deploy to Heroku.
Hope it helps
Migrations are not supposed to create data. They define tables, indexes, constraints, etc.
You should use db:seed, after migrating, to create data (besides adding pg version as mentioned on other answer.)

no such file to load -- pg unable to run migrations manually

I am using pg for dev and test in local machine only
its in dev and test group out in gemfile
group :development, :test do
gem 'pg'
end
rails version is
Rails 3.0.19
ruby 1.8.7
I used moonshine or shorter cut of capistrano
capistrano:deploy
the migrations file can't be migrated using capistrano, throws an error.
I am trying to run migrations manually inside server
bundle exec rake db:migrate VERSION=20140205173759_add_hebrew_to_piles.rb
I have three files and wanted to run rake migrate on each one (got it from stackoverlow, rails run specific migration)
and got
no such file to load -- pg
I am using mysql as production database so I don't understand why is looking for pg inside my server? any help?

Issue when pushing to Heroku. Run `bundle install` elsewhere and add the updated Gemfile.lock to version control

I've been trying to trouble shoot this error now for a couple hours without making any progress. I've tried running bundle install in different environments with no luck. I'm not sure what is happening and I feel as if the error is no longer providing relevant feedback. However, I am using Ruby 1.9.3 and when I push it states that Heroku is using ruby 2.0.0. Could this have something to do with it?
Castillos-MacBook-Pro:reservester-nysum13 castillo$ git push heroku master
Identity added: /Users/castillo/.ssh/id_rsa (/Users/castillo/.ssh/id_rsa)
Counting objects: 66, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (51/51), done.
Writing objects: 100% (66/66), 26.25 KiB, done.
Total 66 (delta 4), reused 38 (delta 1)
-----> Ruby/Rails app detected
-----> Using Ruby version: ruby-2.0.0
-----> Installing dependencies using Bundler version 1.3.2
Running: bundle install --without development:test --path vendor/bundle --binstubs vendor/bundle/bin --deployment
You are trying to install in deployment mode after changing
your Gemfile. Run `bundle install` elsewhere and add the
updated Gemfile.lock to version control.
You have added to the Gemfile:
* debugger
Bundler Output: You are trying to install in deployment mode after changing
your Gemfile. Run `bundle install` elsewhere and add the
updated Gemfile.lock to version control.
You have added to the Gemfile:
* debugger
!
! Failed to install gems via Bundler.
!
! Push rejected, failed to compile Ruby/Rails app
To git#heroku.com:guarded-sierra-5306.git
! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'git#heroku.com:guarded-sierra-5306.git'
gem 'debugger' originally was placed outside of the environment group. I moved it to the development group and reran bundle.
Here is my Gemfile
source 'https://rubygems.org'
gem 'rails', '3.2.13'
gem 'therubyracer'
gem 'twitter-bootstrap-rails'
gem 'carrierwave'
gem 'rmagick'
gem "fog", "~> 1.3.1"
gem "devise"
gem "figaro"
gem "galetahub-simple_captcha", :require => "simple_captcha"
group :development do
gem 'annotate'
gem 'sqlite3'
gem 'rspec-rails', '~> 2.0'
gem 'debugger'
end
group :production do
gem 'pg'
end
group :assets do
gem 'sass-rails', '~> 3.2.3'
gem 'coffee-rails', '~> 3.2.1'
gem 'uglifier', '>= 1.0.3'
end
gem 'jquery-rails'
I got similar error. I tried delete Gemfile.lock file manually, rebundle, push it to git and still no luck.
But finally I make it work by change my rvm version to ruby 2.0.0, precomplie the asset with this command
RAILS_ENV=production bundle exec rake assets:precompile
and delete the Gemfile.lock, rebundle, and push it to github. Last part when you push in to heroku use your branch instead your master, this happen because you not deploying the master branch to heroku master branch with this command:
git push heroku your-branch:master
I had a similar situation. Heroku does not support every ruby version. You may be using an unsupported version.
Check for Heroku Ruby supported versions
Change your local ruby version. For example, if you are using rbenv
rbenv local 2.1.6
bundle install
Push the changes to herokugit push heroku master
You can't expect Heroku to know what version of Ruby you're running locally :-) If you want Heroku to use a particular version, tell it. Add ruby '1.9.3' to your Gemfile for example.
It also looks like you didn't rerun bundle install after putting the gem in development group? Try that.
Then add all the changes to git, commit, and push.
This problem is bacause you commit bad (old) Gemfile.lock to heroku server.
You need to update Gemfile.lock on heroku after adding/removing gems.
Do following steps:
save HEROKU_APP_NAME of existing heroku app ( HEROKU_APP_NAME.herokuapp.com )
remove heroku application from https://dashboard.heroku.com/apps and create new one
rename new heroku app to old HEROKU_APP_NAME
remove Gemfile.lock from your git repo
remove Gemfile.lock form your local project and form .gitignore (if it exist there)
run bundle install
commit changes to git repo ( new created Gemfile.lock )
run git push heroku master

Bundler ignores groups in rails apps

This problem was fixed in 0.9.8, but seems to have recurred in the 1.x branch.
In my Gemfile I have a group for the test and development environments that use the rspec gems.
On my production server rspec is not installed.
I used the command bundle install --without test development in my
rails app
Starting my rails app in production mode gives the exception:
Could not find gem 'rspec (>= 0)' in any of the gem sources listed in
your Gemfile.
If I comment out the test group the same error happens with the development group.
The same problem exists if I start in development mode, then it tries to load the gems in the test group.
It seems that bundler completely ignores the environment groups and tries to load all gems in Gemfile:
group :test do
gem "rspec"
end
group :development do
gem "rspec-rails"
end
versions:
bundle 1.0.15
rails 3.0.7
ruby 1.9.2-p180
I was having this problem too, the problem was that .bundle/config file had something like
"--without development test"
even tho I had never ran the bundle command with this parameters(maybe I cloned the repository from the Webbynode server and their system added this automatically for production...)
anyway, the fix was
rm .bundle/config
bundle install

How to empty a Heroku database

I'm working on a Ruby on Rails 3 webapp on Heroku. How do I empty the database?
To drop the database, if you are using SHARED_DATABASE_URL:
$ heroku pg:reset DATABASE_URL
Now to recreate the database with nothing in it:
$ heroku run rake db:migrate
To populate the database with your seed data:
$ heroku run rake db:seed
---OR---
You can combine the last two (migrate & seed) into one action by executing this:
$ heroku run rake db:setup
Edit 2014-04-18: rake db:setup doesn't work with Rails 4, it fails with a Couldn't create database error.
Edit 2014-10-09: You can use rake db:setup with Rails 4. It does give you a Couldn't create database error (because the database was already created using the heroku pg:reset command). But it also loads your database schema and your seeds after the error message.
You can do this with pretty much any rake command, but there are exceptions. For example, db:reset doesn't work via heroku run rake. You have to use pg:reset instead.
More information can be found in Heroku's documentation:
Running Rake Commands
Reset Postgres DB
Heroku has deprecated the --db option now, so now use:
heroku pg:reset DATABASE_URL --confirm {the name of your app}
It's a little confusing because you use the literal text SHARED_DATABASE but where I have written {the name of your app} substitute the name of your app. For example, if your app is called my_great_app then you use:
heroku pg:reset DATABASE_URL --confirm my_great_app
To drop the database:
$ heroku pg:reset SHARED_DATABASE --confirm NAME_OF_THE_APP
To recreate the database:
$ heroku run rake db:migrate
To seed the database:
$ heroku run rake db:seed
**Final step
$ heroku restart
The current, ie. 2017 way to do this is:
heroku pg:reset DATABASE
https://devcenter.heroku.com/articles/heroku-postgresql#pg-reset
Now the command is
heroku pg:reset DATABASE_URL --confirm your_app_name
this way you can specify which app's db you want to reset.
Then you can run
heroku run rake db:migrate
heroku run rake db:seed
or direct for both above commands
heroku run rake db:setup
And now final step to restart your app
heroku restart
I contacted Heroku support, and they confirmed that it is a bug with the latest gem (I am using heroku-2.26.2)
Charlie - we are aware of this issue with the 'heroku' gem and are
working to fix it.
Here's the issue if you care to follow-along -
https://github.com/heroku/heroku/issues/356
Downgrading to an earlier version of the 'heroku' gem should help. I've been using v2.25.0 for most of today without issue.
Downgrade with the following commands:
gem uninstall heroku
gem install heroku --version 2.25.0
If you already have multiple gems installed, you may be presented with:
Select gem to uninstall:
1. heroku-2.25.0
2. heroku-2.26.2
3. All versions
Just uninstall #2 and rerun the command. Joy!
The complete answer is (for users with multi-db):
heroku pg:info - which outputs
=== HEROKU_POSTGRESQL_RED <-- this is DB
Plan Basic
Status available
heroku pg:reset HEROKU_POSTGRESQL_RED --confirm app_name
More information found in: https://devcenter.heroku.com/articles/heroku-postgresql
Now it's diffrent with heroku. Try:
heroku pg:reset DATABASE --confirm
Now it's also possible to reset the database through their web interface.
Go to dashboard.heroku.com select your app and then you'll find the database under the add-ons category, click on it and then you can reset the database.
Today the command
heroku pg:reset --db SHARED_DATABASE_URL
not working for shared plans, I'm resolve using
heroku pg:reset SHARED_DATABASE
Check your heroku version. I just updated mine to 2.29.0, as follows:
heroku --version
#=> heroku-gem/2.29.0 (x86_64-linux) ruby/1.9.3
Now you can run:
heroku pg:reset DATABASE --confirm YOUR_APP_NAME
Then create your database and seed it in a single command:
heroku run rake db:setup
Now restart and try your app:
heroku restart
heroku open
Login to your DB using
heroku pg:psql and type the following commands:
drop schema public cascade;
create schema public;
In case you prefer to use Heroku Web-site:
Go to https://postgres.heroku.com/databases
Select the database you want to reset
Click on a settings button in the right upper corner
Click "Reset Database" as shown below:
type in "RESET" and press ok
This is what worked for me.
1.clear db.
heroku pg:reset --app YOUR_APP
After running that you will have to type in your app name again to confirm.
2.migrate db to recreate.
heroku run rake db:migrate --app YOUR_APP
3.add seed data to db.
heroku run rake db:seed --app YOUR_APP
Assuming you want to reset your PostgreSQL database and set it back up, use:
heroku apps
to list your applications on Heroku. Find the name of your current application (application_name). Then run
heroku config | grep POSTGRESQL
to get the name of your databases. An example could be
HEROKU_POSTGRESQL_WHITE_URL
Finally, given application_name and database_url, you should run
heroku pg:reset `database_url` --confirm `application_name`
heroku run rake db:migrate
heroku restart
If you are logged in from the console, this will do the job in the latest heroku toolbelt,
heroku pg:reset --confirm database-name
I always do this with the one-liner 'heroku pg:reset DATABASE'.
Best solution for you issue will be
heroku pg:reset -r heroku --confirm your_heroku_app_name
--confirm your_heroku_app_name
is not required, but terminal always ask me do that command.
After that command you will be have pure db, without structure and stuff, after that you can run
heroku run rake db:schema:load -r heroku
or
heroku run rake db:migrate -r heroku