Cannot migrate on Heroku - ruby-on-rails

I'd like to migrate database to production environment on Heroku.
I typed the following code, however I got error. I have no idea what to do. I'm looking forward to your advice. Thank you for your kindness.
$ heroku run rake db:migrate
Running `rake db:migrate --trace` attached to terminal... up, run.2338
rake aborted!
LoadError: libruby.so.2.2: cannot open shared object file: No such file or directory - /app/vendor/bundle/ruby/2.2.0/gems/pg-0.18.2/lib/pg_ext.so
/app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:274:in `require'
/app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:274:in `block in require'
/app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:240:in `load_dependency'
/app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:274:in `require'
/app/vendor/bundle/ruby/2.2.0/gems/pg-0.18.2/lib/pg.rb:4:in `<top (required)>'
/app/vendor/bundle/ruby/2.2.0/gems/bundler-1.9.7/lib/bundler/runtime.rb:76:in `require'
/app/vendor/bundle/ruby/2.2.0/gems/bundler-1.9.7/lib/bundler/runtime.rb:76:in `block (2 levels) in require'
/app/vendor/bundle/ruby/2.2.0/gems/bundler-1.9.7/lib/bundler/runtime.rb:72:in `each'
/app/vendor/bundle/ruby/2.2.0/gems/bundler-1.9.7/lib/bundler/runtime.rb:72:in `block in require'
/app/vendor/bundle/ruby/2.2.0/gems/bundler-1.9.7/lib/bundler/runtime.rb:61:in `each'
/app/vendor/bundle/ruby/2.2.0/gems/bundler-1.9.7/lib/bundler/runtime.rb:61:in `require'
/app/vendor/bundle/ruby/2.2.0/gems/bundler-1.9.7/lib/bundler.rb:134:in `require'
/app/config/application.rb:7:in `<top (required)>'
/app/Rakefile:4:in `require'
/app/Rakefile:4:in `<top (required)>'
/app/vendor/ruby-2.2.2/lib/ruby/2.2.0/rake/rake_module.rb:28:in `load'
/app/vendor/ruby-2.2.2/lib/ruby/2.2.0/rake/rake_module.rb:28:in `load_rakefile'
/app/vendor/ruby-2.2.2/lib/ruby/2.2.0/rake/application.rb:689:in `raw_load_rakefile'
/app/vendor/ruby-2.2.2/lib/ruby/2.2.0/rake/application.rb:94:in `block in load_rakefile'
/app/vendor/ruby-2.2.2/lib/ruby/2.2.0/rake/application.rb:176:in `standard_exception_handling'
/app/vendor/ruby-2.2.2/lib/ruby/2.2.0/rake/application.rb:93:in `load_rakefile'
/app/vendor/ruby-2.2.2/lib/ruby/2.2.0/rake/application.rb:77:in `block in run'
/app/vendor/ruby-2.2.2/lib/ruby/2.2.0/rake/application.rb:176:in `standard_exception_handling'
/app/vendor/ruby-2.2.2/lib/ruby/2.2.0/rake/application.rb:75:in `run'
/app/bin/rake:8:in `<main>'

Have you tried running migration directly from the bash inside the heroku server? If not, try the following...
heroku run bash --app your_app_name_goes_here
bundle exec rake db:migrate
First line of code opens the bash command terminal and the second one migrates the db as usual.
This would not be the suggested solution. But, in case you DO NOT care about losing data in the database, you can try and reset the database first and try again. Again, don't do this unless you are willing to lose existing data!
heroku pg:reset DATABASE
heroku run rake db:migrate
However you can perform this via bash as before.
Hope this helps you out.

You can run a dyno in the background using heroku run:detached. Unlike heroku run, these dynos will send their output to your logs instead of your console window. You can use heroku logs to view the output from these commands:$ heroku run:detached rake db:migrate
Running rake db:migrate... up, run.2
Use 'heroku logs -p run.2' to view the log output.

Related

Rails database migration error

I wanna get started with ror but this problem seems unsolvable. I know there are many threads about it this database error but none of the solutions appear to work out. I now searched through the forums all afternoon, with no success.
I basically just perform the first tasks from the textbook, which are as follows:
I create a new RoR project (Windows 10, SQLite3) with
rails new depot
Then I create a scaffold in this project with the following code:
rails generate scaffold Product title:string description:text image_url:string price:decimal
And as i test the application I get the db:migrate error. I tried rake db:migrate, db:rollback, db:drop and then db:create, I checked the migration file for mistakes, but nothing appears to work.
I assume the solution should be quite simple, since the application should be as uncomplex as it gets at this state, but I just cannot get behind the secret it appears.
Migrations are pending. To resolve this issue, run:
bin/rails db:migrate RAILS_ENV=test
from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/activerecord-5.0.1/lib/active_record/migration.rb:586:in `load_schema_if_pending!'
from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/activerecord-5.0.1/lib/active_record/migration.rb:592:in `block in maintain_test_schema!'
from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/activerecord-5.0.1/lib/active_record/migration.rb:823:in `suppress_messages'
from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/activerecord-5.0.1/lib/active_record/migration.rb:597:in `method_missing'
from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/activerecord-5.0.1/lib/active_record/migration.rb:592:in `maintain_test_schema!'
from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/railties-5.0.1/lib/rails/test_help.rb:15:in `<top (required)>'
from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/activesupport-5.0.1/lib/active_support/dependencies.rb:293:in `require'
from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/activesupport-5.0.1/lib/active_support/dependencies.rb:293:in `block in require'
from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/activesupport-5.0.1/lib/active_support/dependencies.rb:259:in `load_dependency'
from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/activesupport-5.0.1/lib/active_support/dependencies.rb:293:in `require'
from C:/Users/Flori/Desktop/bsp/test/test_helper.rb:3:in `<top (required)>'
from C:/Users/Flori/Desktop/bsp/test/controllers/products_controller_test.rb:1:in `require'
from C:/Users/Flori/Desktop/bsp/test/controllers/products_controller_test.rb:1:in `<top (required)>'
from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/railties-5.0.1/lib/rails/test_unit/test_requirer.rb:11:in `require'
from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/railties-5.0.1/lib/rails/test_unit/test_requirer.rb:11:in `block in require_files'
from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/railties-5.0.1/lib/rails/test_unit/test_requirer.rb:10:in `each'
from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/railties-5.0.1/lib/rails/test_unit/test_requirer.rb:10:in `require_files'
from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/railties-5.0.1/lib/rails/test_unit/minitest_plugin.rb:86:in `plugin_rails_init'
from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/minitest-5.10.1/lib/minitest.rb:80:in `block in init_plugins'
from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/minitest-5.10.1/lib/minitest.rb:78:in `each'
from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/minitest-5.10.1/lib/minitest.rb:78:in `init_plugins'
from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/minitest-5.10.1/lib/minitest.rb:129:in `run'
from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/railties-5.0.1/lib/rails/test_unit/minitest_plugin.rb:73:in `run'
from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/minitest-5.10.1/lib/minitest.rb:62:in `block in autorun'
Switch of your server, then run
rake db:drop db:create db:migrate
This must fix your problem

Heroku Rake and Heroku Push Not Working - Rails

If i try running: heroku rake db:migrate, this is the error i get:
rake aborted!
undefined local variable or method `config' for main:Object
/app/config/application.rb:4:in `<top (required)>'
/app/Rakefile:4:in `require'
/app/Rakefile:4:in `<top (required)>'
/app/vendor/bundle/ruby/2.0.0/gems/rake-10.1.0/lib/rake/rake_module.rb:25:in `load'
/app/vendor/bundle/ruby/2.0.0/gems/rake-10.1.0/lib/rake/rake_module.rb:25:in `load_rakefile'
/app/vendor/bundle/ruby/2.0.0/gems/rake-10.1.0/lib/rake/application.rb:637:in `raw_load_rakefile'
/app/vendor/bundle/ruby/2.0.0/gems/rake-10.1.0/lib/rake/application.rb:94:in `block in load_rakefile'
/app/vendor/bundle/ruby/2.0.0/gems/rake-10.1.0/lib/rake/application.rb:165:in `standard_exception_handling'
/app/vendor/bundle/ruby/2.0.0/gems/rake-10.1.0/lib/rake/application.rb:93:in `load_rakefile'
/app/vendor/bundle/ruby/2.0.0/gems/rake-10.1.0/lib/rake/application.rb:77:in `block in run'
/app/vendor/bundle/ruby/2.0.0/gems/rake-10.1.0/lib/rake/application.rb:165:in `standard_exception_handling'
/app/vendor/bundle/ruby/2.0.0/gems/rake-10.1.0/lib/rake/application.rb:75:in `run'
/app/vendor/bundle/ruby/2.0.0/gems/rake-10.1.0/bin/rake:33:in `<top (required)>'
/app/vendor/bundle/ruby/2.0.0/bin/rake:23:in `load'
/app/vendor/bundle/ruby/2.0.0/bin/rake:23:in `<main>
Running: git push heroku master i get this:
Preparing app for Rails asset pipeline
Running: rake assets:precompile
rake aborted!
could not connect to server: Connection refused
Is the server running on host "127.0.0.1" and accepting
TCP/IP connections on port 5432?
I have tried adding: config.assets.initialize_on_precompile = false to application.rb but it did not help :(.
This app i'm trying to push used to be on heroku, but i accidentally deleted my herokuapp. Please help!
The problem was with Rolify, new version has problems so I had to step down back to 3.2.0.

what does it do by "bundle exec rake db:migrate"?

from my research, bundle exec is responsible for executing a command in the context of a bundle.
anyway, I don't quite understand yet for what it does differently for just the command rake db:migrate comparing with bundle exec rake db:migrate.
for example in my case, I executed the first command, and what I got was the following errors:
$ rake db:migrate
(in c:/rails/rails_projects/soccerweb)
rake aborted!
uninitialized constant Rake::DSL
c:/Ruby192/lib/ruby/1.9.1/rake.rb:2482:in `const_missing'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/tasklib.rb:8:in `<clas
s:TaskLib>'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/tasklib.rb:6:in `<modu
le:Rake>'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/tasklib.rb:3:in `<top
(required)>'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/testtask.rb:4:in `requ
ire'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/testtask.rb:4:in `<top
(required)>'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.1.1/lib/rails/test_unit/testing.r
ake:2:in `require'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.1.1/lib/rails/test_unit/testing.r
ake:2:in `<top (required)>'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.1.1/lib/rails/test_unit/railtie.r
b:12:in `load'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.1.1/lib/rails/test_unit/railtie.r
b:12:in `block in <class:TestUnitRailtie>'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.1.1/lib/rails/railtie.rb:183:in `
call'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.1.1/lib/rails/railtie.rb:183:in `
block in load_tasks'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.1.1/lib/rails/railtie.rb:183:in `
each'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.1.1/lib/rails/railtie.rb:183:in `
load_tasks'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.1.1/lib/rails/engine.rb:396:in `b
lock in load_tasks'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.1.1/lib/rails/application/railtie
s.rb:8:in `each'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.1.1/lib/rails/application/railtie
s.rb:8:in `all'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.1.1/lib/rails/engine.rb:396:in `l
oad_tasks'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.1.1/lib/rails/application.rb:103:
in `load_tasks'
c:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.1.1/lib/rails/railtie/configurabl
e.rb:30:in `method_missing'
c:/rails/rails_projects/soccerweb/Rakefile:7:in `<top (required)>'
c:/Ruby192/lib/ruby/1.9.1/rake.rb:2373:in `load'
c:/Ruby192/lib/ruby/1.9.1/rake.rb:2373:in `raw_load_rakefile'
c:/Ruby192/lib/ruby/1.9.1/rake.rb:2007:in `block in load_rakefile'
c:/Ruby192/lib/ruby/1.9.1/rake.rb:2058:in `standard_exception_handling'
c:/Ruby192/lib/ruby/1.9.1/rake.rb:2006:in `load_rakefile'
c:/Ruby192/lib/ruby/1.9.1/rake.rb:1991:in `run'
c:/Ruby192/bin/rake:31:in `<main>'
but when I used "bundle exec" preceding that "rake db:migrate" command, everything just worked for me gracefully!
anyone can shed some light on me?
bundle exec rake runs the version of rake which you've specified in your Gemfile. The default version of rake, the one which can be found in your $PATH, might be different than one executed by bundle exec rake.
The problem you've experienced has been covered in a separate question. Your bundle exec rake most probably runs rake 0.8.7 and rake from your $PATH is a newer version which is affected by this problem.
Quoting from man bundle exec:
bundle exec makes a number of changes to the shell environment, then executes the command you specify in full.
(...)
put the directory containing executables (like rails, rspec, rackup) for your bundle on $PATH
Bundler solves gem dependencies for you. You can find read their rationale page for an explanation about their approach.

how to use app from github

I want to use app from github , i cloned it ,
but when i try bundle install , it requires a gem file .
I copied my gem file from other Local app , 'bundle install ' is successfull , but when i try 'rake db:migrate' i see it:
rusik#rusik-K50AF:~/work/ruby/episode-119/blog$ rake db:migrate
rake aborted!
no such file to load -- initializer
(See full trace by running task with --trace)
rusik#rusik-K50AF:~/work/ruby/episode-119/blog$ rake db:migrate --trace
rake aborted!
no such file to load -- initializer
/home/rusik/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:55:in `require'
/home/rusik/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:55:in `require'
/home/rusik/work/ruby/episode-119/blog/config/boot.rb:54:in `load_initializer'
/home/rusik/work/ruby/episode-119/blog/config/boot.rb:38:in `run'
/home/rusik/work/ruby/episode-119/blog/config/boot.rb:11:in `boot!'
/home/rusik/work/ruby/episode-119/blog/config/boot.rb:109:in `<top (required)>'
/home/rusik/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
/home/rusik/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
/home/rusik/work/ruby/episode-119/blog/Rakefile:4:in `<top (required)>'
/home/rusik/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2.2/lib/rake/rake_module.rb:25:in `load'
/home/rusik/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2.2/lib/rake/rake_module.rb:25:in `load_rakefile'
/ home/rusik/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2.2/lib/rake/application.rb:501:in `raw_load_rakefile'
/home/rusik/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2.2/lib/rake/application.rb:82:in `block in load_rakefile'
/home/rusik/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/home/rusik/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2.2/lib/rake/application.rb:81:in `load_rakefile'
/home/rusik/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2.2/lib/rake/application.rb:65:in `block in run'
/home/rusik/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/home/rusik/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2.2/lib/rake/application.rb:63:in `run'
/home/rusik/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2.2/bin/rake:33:in `<top (required)>'
/home/rusik/.rvm/gems/ruby-1.9.2-p290/bin/rake:19:in `load'
/home/rusik/.rvm/gems/ruby-1.9.2-p290/bin/rake:19:in `<main>'
,
I tried to copy my db test.sqlite3 from my LOCAL app, but it doesn't work, the same problem.
So ,of'course, i tried rails server, but it doesn't work.
So , how to setup app from github?
It's rails 2 app, so there is no bundler at all. If you want to run it you should read README:
To setup the app, just run rake setup.

deploying rails app to heroku migrations rake error on windows

I am attempting to deploy my app to heroku via a windows 7 machine.
I've made it as far as git push heroku master without running into any major issues but when I try to rake the migrations i get the following error
$ heroku rake db:migrate --trace
rake aborted!
No such file or directory - /disk1/tmp/13403_23723015091620/.bundle/gems/specifi
cations/activesupport-2.3.8.gemspec
/disk1/home/slugs/211056_9194ad5_13a9/mnt/.bundle/environment.rb:178:in `read'
/disk1/home/slugs/211056_9194ad5_13a9/mnt/.bundle/environment.rb:178
/disk1/home/slugs/211056_9194ad5_13a9/mnt/.bundle/environment.rb:147:in `map'
/disk1/home/slugs/211056_9194ad5_13a9/mnt/.bundle/environment.rb:147
/usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
/usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
/disk1/home/slugs/211056_9194ad5_13a9/mnt/config/../config/preinitializer.rb:3
/disk1/home/slugs/211056_9194ad5_13a9/mnt/config/boot.rb:28:in `load'
/disk1/home/slugs/211056_9194ad5_13a9/mnt/config/boot.rb:28:in `preinitialize'
/disk1/home/slugs/211056_9194ad5_13a9/mnt/config/boot.rb:10:in `boot!'
/disk1/home/slugs/211056_9194ad5_13a9/mnt/config/boot.rb:129
/usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
/usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require' /disk1/home/slugs/211056_9194ad5_13a9/mnt/Rakefile:4
/home/slugs/211056_9194ad5_13a9/mnt/.bundle/gems/gems/rake-0.8.7/lib/rake.rb:2383:in `load'
/home/slugs/211056_9194ad5_13a9/mnt/.bundle/gems/gems/rake-0.8.7/lib/rake.rb:238
3:in `raw_load_rakefile'
/home/slugs/211056_9194ad5_13a9/mnt/.bundle/gems/gems/rake-0.8.7/lib/rake.rb:2017:in `load_rakefile'
/home/slugs/211056_9194ad5_13a9/mnt/.bundle/gems/gems/rake-0.8.7/lib/rake.rb:2068:in `standard_exception_handling'
/home/slugs/211056_9194ad5_13a9/mnt/.bundle/gems/gems/rake-0.8.7/lib/rake.rb:2016:in `load_rakefile'
/home/slugs/211056_9194ad5_13a9/mnt/.bundle/gems/gems/rake-0.8.7/lib/rake.rb:2000:in `run'
/home/slugs/211056_9194ad5_13a9/mnt/.bundle/gems/gems/rake-0.8.7/lib/rake.rb:2068:in `standard_exception_handling'
/home/slugs/211056_9194ad5_13a9/mnt/.bundle/gems/gems/rake-0.8.7/lib/rake.rb:1998:in `run'
/home/slugs/211056_9194ad5_13a9/mnt/.bundle/gems/gems/rake-0.8.7/bin/rake:31
/usr/local/bin/rake:19:in `load'
/usr/local/bin/rake:19
(in /disk1/home/slugs/211056_9194ad5_13a9/mnt)
I should mention, though it could be determined from the above code, that I am using bundler. Perhaps it is due to this.
I'm at a total loss as to what this could mean. I came across this SO thread, but all the fixes it presented I had already tried and they didn't work. I am beginning to appreciate why rails deployment is derided so. Any suggestions?
Did you already take a look on Heroku's documentation about Bundler at http://docs.heroku.com/bundler ?
Are you sure that your Gemfile and Gemfile.lock files are added to your git repository?
I'm able to duplicate this problem:
http://github.com/heroku/heroku/issues#issue/30
The same Rails app will deploy via OS X.

Resources