Deploying a Rails3 app, and am having some issues getting rake to find the gems installed by 'bundle install --deployment':
$ rake db:migrate
(in /home/jrdev/rails/testapp)
rake aborted!
!!! Missing the mysql2 gem. Add it to your Gemfile: gem ‘mysql2’
But, that gem in is the Gemfile, and is also in the vendor/bundle folder…
$ bundle show mysql2
/home/jrdev/rails/testapp/vendor/bundle/ruby/1.8/gems/mysql2-0.2.6
My .gemrc file:
gemhome: /home/jrdev/.gems
gempath:
- /home/jrdev/.gems
- /usr/lib/ruby/gems/1.8
I thought rails3 apps already had the bundler code to detect which gems to use? I know I'm using the right rake, too (rake db:migrate --trace starts in /home/jrdev/rails/testapp/vendor/bundle/ruby/1.8/bin/rake). Same result using bundler's exec.
:(
Wouldn't you freaking know I solve it a minute after asking.
My database.yml file was still calling the 'mysql' adapter instead of 'mysql2'.
Still, what an OBSCURE error message!
In /home/jrdev/rails/testapp, you should find a file called Gemfile. Look into it and just add the line
gem 'mysql2'
somewhere.
Related
I've been running a Rails 3.2 with Ruby 1.9.3 for a while now. Recently I added Rails 5.1 and Ruby 2.4.
I used rvm to install Ruby2.4.
Today I had occasion to cd into one of my old projects and run rake db:migrate, and I got the following message:
Gem::LoadError: You have already activated rake 12.0.0, but your Gemfile requires rake 0.9.2.2. Prepending `bundle exec` to your command may solve this.
Prepending 'bundle exec' did solve the problem but for my knowledge I would like to understand what happened. I thought the whole point of a Gem file within the project was to lock in the required gems.
So somewhere on my machine clearly there is still rake 0.9.2.2 but why did my command 'rake db:migrate' not use that automatically?
Reason: Some of the gem might have locked rake gem to that version.You are getting this as version of rake inside gemlock file is different than the one you have already installed.
Solution1:
bundle update
Solution2:
edit the gemlock file. open Gemfile.lock and change
rake (0.9.2.2) to rake (12.0.0)
Solution3:
remove Gemfile.lock and run bundle install once again.This will create
Gemfile.lock once again.
im having this issue when i try to deploy my ruby on rails application to heroku, i check different posts here, because i saw this issue before but i couldnt fix it.
when i try to run:
$ heroku rake db:migrate
I get a lot of these ones: DEPRECATION WARNING:
and then:
rake aborted!
Please install the postgresql adapter: `gem install activerecord-postgresql-adapter` (pg is not part of the bundle. Add it to Gemfile.)
Tasks: TOP => db:migrate => db:load_config
(See full trace by running task with --trace)
I tried to change my Gemfile with 'pg' and my group :assets do to :production, i know im missing something but i could'nt figured out what.
Some ideas?
Also when I go to the app url, I get this:
Application Error
An error occurred in the application and your page could not be served. Please try again in a few moments.
If you are the application owner, check your logs for details.
Thanks in advance for any suggest and help!!!
You have to use Postgres on Heroku, you can't use sqlite3 because Heroku prohibits you from saving to the file system. So add the pg gem to your production bundle and re-deploy then your migrations should run.
Answer here is simple, add the following production in your gemfile as:
group :production do
gem 'pg'
end
Your local machine won't work with this production, so we now have to bundle it by ignoring PostgreSQL gem which can be done as:
bundle install --without production
After this, try heroku rake db:migrate. Must work.
Good luck
I have been pulling out my hair trying to get this to work. Any experience or info would be very appreciated.
When trying to recompile Rails 3.1 assets locally (before I push to Heroku) I get the error:
rake assets:precompile --trace
** Invoke assets:precompile (first_time)
** Execute assets:precompile
rake aborted!
Please install the pg adapter: `gem install activerecord-pg-adapter'
(no such file to load --active_record/connection_adapters/pg_adapter)
Then when I go to install the gem I get an error:
Could not find a valid gem 'activerecord-postgresql-adapter' (>= 0) in any repository
Any help greatly appreciated, this is causing me gray hairs.
Looks like this answer may help:
How to handle Ruby on Rails error: "Please install the postgresql adapter: `gem install activerecord-postgresql-adapter'"
It looks like the gem is called "pg", so: gem install pg
You may also want to check your database.yml file, as the first answer in the linked post suggests.
When trying to rake db:migrate on Heroku. I'm getting the following error.
rake aborted!
uninitialized constant Rake::DSL
From what I've gathered this seems to be a bug with Rake 0.9.2. If I do "gem list" locally only Rake (0.8.7) appears to be installed.
I've tried adding "gem 'rake', '0.8.7'" to my gem file and running bundle install but then I get the following error.
You have requested:
rake = 0.8.7
The bundle currently has rake locked at 0.9.2.
Try running `bundle update rake`
If I do run bundle update rake, it reverts back to 0.9.2, and I'm back where I started.
Am I missing something obvious here?
You should run commands with bundle exec to ensure your getting the proper dependencies. So run:
bundle exec rake db:migrate
For a more detailed post see Yehuda Katz blog post http://yehudakatz.com/2011/05/30/gem-versioning-and-bundler-doing-it-right/
If you still continue to have problems there appears to be several other people with the same issue How to fix the uninitialized constant Rake::DSL problem on Heroku? which they resolved by adding the following to their Rakefile:
require 'rake/dsl_definition'
require 'rake'
I got this error when doing "heroku rake db:migrate".
In /app:
rake aborted!
uninitialized constant Rake::DSL
/usr/ruby1.9.2/lib/ruby/1.9.1/rake.rb:2482:in `const_missing'
....
...
....
..
etc...
I fixed it by adding
require 'rake/dsl_definition'
in RakeFile and then typed in
bundle update rake
git add .
git commit -m "Change RakeFile"
git push heroku
heroku rake db:migrate
This one solved my problem. I didn't add gem 'rake', '0.8.7' in my gem file
and my gem list shows rake (0.9.2, 0.8.7).
I have a blog post about this, You have already activated Rake 0.9.2. There are two ways to do this:
Only use the older version of Rake:
Check out your current Rake versions with $ gem list. See which versions of Rake you have and remove them all except for0.8.7. You can remove the gems with gem uninstall rake -v=0.9.1 or whatever version you need to remove.
Or just add a one liner to your Rake file:
Unless you have to use the older version of Rake it is easier to add this linerequire 'rake/dsl_definition' to your Rails's app Rakefile.
require File.expand_path('../config/application', __FILE__)
require 'rake/dsl_definition'
require 'rake'
I used this to solve this very problem earlier without deleting any gems. This method will force your app to use Rake 0.8.7 which is more stable than 0.9+. You must run bundle update rake command after specifying the version of Rake to use so your gemfile.lock file is in sync with your gem file (if you skip this step Heroku will not let you push your code!)
In your gem file specify the version of Rake to use:
"rake", "0.8.7"
Then do:
bundle update rake
If this still isn't working for you, then do:
sudo gem uninstall rake
As with rich's answer (solving this problem without deleting any gems), but with a correction to your step 1., and a few additional steps:
In the gem file specify:
gem 'rake', '0.8.7'
bundle install (Bundler documentation say to always 'bundle install' after changing your gem file)
git commit -am "Fixed heroku rake problem by specifying rake 0.8.7 in Gemfile"
git push heroku
heroku rake db:migrate
I got the same error without steps 3 and 4.
Pranay-Tares-MacBook-Pro:music_library pranaytare$ rake db:migrate
(in /Users/pranaytare/Sites/music_library)
!!! The bundled mysql.rb driver has been removed from Rails 2.2. Please install the mysql gem and try again: gem install mysql.
rake aborted!
no such file to load -- mysql
(See full trace by running task with --trace)
I got this error while running rake in ROR.. plz help..
I recently installed mysql on my Mac and configured it.
Either install the gem as the error message says, or put the mysql gem in your Gemfile and run bundle install. In the Gemfile, it would be like :
gem 'mysql2'