Couldn't run migration after spring update in Rails - ruby-on-rails

I am facing a error when I run any migration as:
raj#notebook-pc:~/Desktop/Projects/invoicemanagement$ rails g migration RemoveDescriptionOfGoodsFromInvoiceDetails description_of_goods:string
Warning: You're using Rubygems 1.8.23 with Spring. Upgrade to at least Rubygems 2.1.0 and run `gem pristine --all` for better startup performance.
/var/lib/gems/1.9.1/gems/bundler-1.9.0/lib/bundler/runtime.rb:34:in `block in setup': You have already activated spring 1.3.3, but your Gemfile requires spring 1.3.2. Prepending `bundle exec` to your command may solve this. (Gem::LoadError)
from /var/lib/gems/1.9.1/gems/bundler-1.9.0/lib/bundler/runtime.rb:19:in `setup'
** 11 stack trace lines skipped **
from /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:35:in `require'
So with some googling I run bundle update spring, which solved the above error, and I am able to remove/add migrations. Again if I run rake db:migrate, I am getting error as:
rake aborted!
StandardError: An error has occurred, this and all later migrations canceled:
undefined method `to_sym' for nil:NilClass/var/lib/gems/1.9.1/gems/activerecord-4.1.4/lib/active_record/connection_adapters/abstract/schema_definitions.rb:216:in `column'
** 33 stack trace lines skipped **
/var/lib/gems/1.9.1/gems/activerecord-4.1.4/lib/active_record/railties/databases.rake:34:in `block (2 levels) in <top (required)>'
Tasks: TOP => db:migrate
Please help me.

After running bundle update and updating Spring, I was getting the following error when running the console:
There is a version mismatch between the spring client and the server.
You should restart the server and make sure to use the same version.
CLIENT: 1.3.4, SERVER: 1.3.3
I followed the recommendations in this Github issue and ran:
spring stop
This fixed the issue for me.

try running "bundle update" in your terminal, then try "rails console" again as usual - i had this same issue , running bundle update first fixed it for me!

Run: ps aux | grep spring, then kill the spring process.
It worked for me.

I had a similar problem trying to run rails commands outside of my docker container.
In my case, my Gemfile.lock file said to use Spring (1.3.4), but the error message said my server was running version 1.3.5. Prepending my command with bundle exec didn't make any difference either. By running
gem list | grep spring
I noticed I had multiple versions installed. After I ran
gem uninstall spring -v '1.3.5'
and bundle again, it worked perfectly.
Who knows, I may have needed the newer version for some other project at some time.

This happens because one of the dependencies of your project is an older version of Spring than is installed on your system:
You have already activated spring 1.3.3, but your Gemfile requires spring 1.3.2. Prepending `bundle exec` to your command may solve this. (Gem::LoadError)
The correct way to deal with this is to prepend bundle exec to your command, as the error message indicates. Please see below:
When running an executable, ALWAYS use bundle exec [command]. Quoting from the bundler documentation: In some cases, running executables without bundle exec may work, if the executable happens to be installed in your system and does not pull in any gems that conflict with your bundle. However, this is unreliable and is the source of considerable pain.
http://yehudakatz.com/2011/05/30/gem-versioning-and-bundler-doing-it-right/
Running bundle update can cause some other issues. If your second error persists, you might want to revert to your old Gemfile from version control.

Stop the spring server
spring stop

Related

Solidus: [Spree WARNING] Missing migrations

I have a problem with Solidus 2.10.2 where when I run rails g spree:install several migration errors come up. Starting with [Spree WARNING] Missing migrations. and ending with [Spree WARNING] Run bundle exec rake railties:install:migrations to get them. but when I run bundle exec rake railties:install:migrations nothing happens...
I tried deleting the database (rails db:drop) and all my custom migration files as well before running the spree generator again however I get the same results. I put the full error in a bitbucket snippet (https://bitbucket.org/goldenBoySailsLow/workspace/snippets/5LGqez) I would appreciate any help
system info: rails 5.2.4.4, ruby 2.7.2, ImageMagick 6.9.10-23 and sqlite3 3.31.1 running on ubuntu 20.04 lts
I just had the same issue because I forgot to specify the version in the Gemfile. When I deployed, it started using solidus 2.11.2 instead of 2.10.2.
Specifying the version solved the problem for me.

Ruby rake loaderror - bundle exec rake not working

I'm trying to run the command rake db:migrate but I keep getting this error:
/Users/[name]/.rvm/gems/ruby-2.2.1/bin/rake:23:in `load': cannot load such file -- /Users/[name]/.rvm/rubies/ruby-2.2.1/lib/ruby/gems/2.2.0/specifications/default/bin/rake (LoadError)
from /Users/[name]/.rvm/gems/ruby-2.2.1/bin/rake:23:in `<main>'
from /Users/[name]/.rvm/gems/ruby-2.2.1/bin/ruby_executable_hooks:15:in `eval'
from /Users/[name]/.rvm/gems/ruby-2.2.1/bin/ruby_executable_hooks:15:in `<main>'
Trying bundle exec rake db:migrate also gives me the same error.
Is there a way I can solve this issue? (I'm on Mac OS X 10.10.5)
EDIT: The first letter of my [name] in the error is upper case even though in my system, it's lower case.
EDIT [PARTIALLY SOLVED]: So I was using Ruby version 2.2.1 and I was supposed to use 2.1.2. Although this did not fix the rake command error, I was trying to run rails server which successfully ran after changing my Ruby version.
If none of the above mentioned comments worked for you, then I suspect you may need to update rake gem. Try:
bundle update rake
See if that fixes the issue. If not, let me know. I will update the answer.
/bin/ruby_executable_hooks.rb error indicates that the error is coming from a Bundler hook. Try to delete the .bundle directory in your project root path and see if the error is gone.

Issue with bundler (ruby)

When I run this command (step 5 of Redmine installation):
bundle exec rake generate_secret_token
I get this error message:
bundler: command not found: rake
Install missing gem executables with `bundle install`
But rake is already installed.
Can somebody help me?
Thanks a lot.
Notes:
1) 'bundle install --local' works fine
2) 'rake' didn't exist originally (what quite surprised me as I took the original redmine Gemfile), so I added the line. Same effect, sadly.
3) 'rake' alone works fine. It's when I write the whole command that I get this message
You should run bundle install. It will download and install all gems required for running application.

Rails: You have already activated rake 10.3.1, but your Gemfile requires rake 10.2.2 (Gem::LoadError)

Here is my error:
rake aborted!
Gem::LoadError: You have already activated rake 10.3.1, but your Gemfile requires rake 10.2.2. Prepending `bundle exec` to your command may solve this.
/Users/AaronWilliamson/.gem/ruby/2.1.0/gems/bundler-1.5.3/lib/bundler/runtime.rb:34:in `block in setup'
/Users/AaronWilliamson/.gem/ruby/2.1.0/gems/bundler-1.5.3/lib/bundler/runtime.rb:19:in `setup'
/Users/AaronWilliamson/.gem/ruby/2.1.0/gems/bundler-1.5.3/lib/bundler.rb:119:in `setup'
/Users/AaronWilliamson/.gem/ruby/2.1.0/gems/bundler-1.5.3/lib/bundler/setup.rb:7:in `<top (required)>'
/Users/AaronWilliamson/Desktop/Ripelist-Classifieds/config/boot.rb:4:in `<top (required)>'
/Users/AaronWilliamson/Desktop/Ripelist-Classifieds/config/application.rb:1:in `<top (required)>'
/Users/AaronWilliamson/Desktop/Ripelist-Classifieds/Rakefile:4:in `<top (required)>'
LoadError: cannot load such file -- bundler/setup
/Users/AaronWilliamson/Desktop/Ripelist-Classifieds/config/boot.rb:4:in `<top (required)>'
/Users/AaronWilliamson/Desktop/Ripelist-Classifieds/config/application.rb:1:in `<top (required)>'
/Users/AaronWilliamson/Desktop/Ripelist-Classifieds/Rakefile:4:in `<top (required)>'
(See full trace by running task with --trace)
I can't run any rake tasks and this seems to be the root of all my other problems. It wasn't like this a couple days ago when I was running rake commands. Can anyone explain what's going on here and how to get my app back on track? I've hit a wall. Also, bundle exec doesn't fix the root of the problem for me. I never had to do that in the past and it's still not working now.
EDIT 2:
You should look at bundle update and change your workflow a little. Refer to this question for further assistance.
Original answer
This is a simple issue which happens when your gemset has a rake version that is newer than the version number your Gemfile.lock mentions.
As is mentioned in the error message, you can use bundle exec to get things working.
My solution in such cases is to just remove Gemfile.lock if I am not too worried other gem versions and their endless dependencies. Otherwise, you can try just removing the one line in Gemfile.lock which talks about the version of rake. run bundle install and the world should be a happy place again. (edit 2: Run bundle update --source instead of this. Don't do this.)
PS: Try using gemsets and organising your gems with rvm for different projects.
Edit
I prefer using rbenv now for managing installations and all gems for a project reside in vendor/bundle using bundle install --path option. Later scope every gem command with bundle exec.
Hence, rails s becomes bundle exec rails s. A little more typing is, in my opinion, better if it means that things will remain clean and conflicts such as this one don't happen.
A simple solution that worked for me is to simply run bundle update rake.
You can use rubygems-bundler to solve this. Run the following commands:
$ gem install rubygems-bundler
$ gem regenerate_binstubs
Then try your rake again.
I had a similar issue and I was skeptical about removing a line from my Gemfile.lock, it seemed hacky and the inconvenience of prepend bundle exec to every rake command was not an option either. I fixed this by first going into my Gemfile.lock to see what version of rake was there (in my case it was 11.1.2). My thought was to uninstall rake and install this version. Running gem uninstall rake gave this output:
Select gem to uninstall:
rake-10.5.0
rake-11.1.1
rake-11.1.2
rake-11.2.2
rake-11.3.0
All versions
I uninstalled both rake-11.2.2 and rake-11.3.0. That fixed my problem
Use this:
gem install rake -v "version-you-want"
My error message:
~ $ rake db:migrate [2.6.5][10:21:00]
rake aborted!
Gem::LoadError: You have already activated rake 12.3.2, but your Gemfile requires rake 13.0.1. Prepending `bundle exec` to your command may solve this.
/Users/torvalds/workspace/ekohe/whitespace/config/boot.rb:5:in `<top (required)>'
/Users/torvalds/workspace/ekohe/whitespace/config/application.rb:3:in `require_relative'
/Users/torvalds/workspace/ekohe/whitespace/config/application.rb:3:in `<top (required)>'
/Users/torvalds/workspace/ekohe/whitespace/Rakefile:6:in `require_relative'
/Users/torvalds/workspace/ekohe/whitespace/Rakefile:6:in `<top (required)>'
(See full trace by running task with --trace)
I am using the rbenv to manage my Ruby environment.
My global Ruby version is as know as the default Ruby version is 2.7.1, because I set it as rbenv global 2.7.1. However, my rake under Ruby 2.7.1 is 12.3.2
~ $ rake --version
rake, version 12.3.2
My project Ruby version is 2.6.5. however, my rake under Ruby 2.6.5 in my project is 13.0.1
~ $ bundle exec rake --version
rake, version 13.0.1
so I have to uninstall global rake
~ $ gem uninstall rake
and reinstall it back
~ $ gem install rake
Fetching rake-13.0.1.gem
Successfully installed rake-13.0.1
1 gem installed
it works! ~~~
I'm not sure whether it will have an influence on other projects. However, so far it works.
According to this solution (that worked for me) : https://stackoverflow.com/a/23668399/4260090
You can solve it by using rubygems-bundler
Type these commands in your terminal :
$ gem install rubygems-bundler
$ gem regenerate_binstubs
It should work now
Try to install nodejs, this was solved my problem.
If you're on ubuntu run this command.
sudo apt-get install nodejs
I tried another way which is delete Gemfile.lock then run bundle install. After that I run rake db:migrate. And everything works fine.
Although I don't think remove Gemfile.lock is bad practice, but may be; who know.
As mentioned on earlier answers this is a simple issue which happens when your gemset has a rake version that is newer than the version number your Gemfile.lock mentions.
The easiest way to debug this is to run bundle update.
The other ways could be to remove Gemfile.lock and running bundle install or simply deleting the line in Gemfile.lock that corresponds to the rake version and try bundle install. But this might sometimes corrupt the Gemfile. I would prefer the first method because it is the safest and the easiest.
Go in the Gemfile.lock, find the rake file and update the version there.
I got this error:
Gem::LoadError: You have already activated rake 11.2.2, but your
Gemfile requires rake 11.1.2. Prepending bundle exec to your command
may solve this.
What I did was to change the version of rake in the Gemfile.lock from:
rake (11.1.2) to rake (11.2.2).
Everything worked fine after that.
I had the same error:
You have already activated rake 12.0.0, but your Gemfile requires rake 11.3.0. Prepending "bundle exec" to your command may solve this.
I solved it by running bundle update
this updated the rake version to my activated rake version and everything worked I hope that works for you!
I meet the similar problem.
My solution is change the line of rake version "gem 'rake', '~> 10.3'" in file Gemfile, delete Gemfile.lock and run 'bundler install', the new Gemfile.lock will show the new version 10.3.1. Then everything will be fine.
I have fixed by simply prepending bundle exec as
"bundle exec rake db:create" or migrate
I experienced this issue:
Here's my solution:
Solution 1:
This solution works a lot of the time, simply update the gem causing the issue, say the gem is rack
bundle update rack
Solution 2:
In some cases Solution 1 may not work, and you will need to edit your Gemfile.lock file.
Simply, open your Gemfile.lock file and then change the version to the update requested.
In my case, the gem was rack, I had rack 2.0.7 defined in my Gemfile.lock file, but my application required rack 2.1.2, I simply had to modify it to rack 2.1.2 in the Gemfile.lock file.
I then had to uninstall the previous version of rack which is rack 2.0.7
gem uninstall rack -v 2.0.7
And finally installed the new gem in production
bundle install --without development test
Solution 3:
In very rare cases Solution 1 and Solution 2 may not work, and you will need to edit your Gemfile before updating the gem.
In my case, the gem was puma, I had puma ~> 3.11 defined in my Gemfile, but my application required puma ~> 4.3.1. At this point running bundle update puma and editing my Gemfile.lock file didn't work, since puma ~> 3.11 version specified in the Gemfile would not allow an update to puma ~> 4.3.1.
I simply had to change the version of puma in the Gemfile to puma ~> 4.3.1 and then ran the command.
bundle update puma
Solution 4:
If the version of rake that your Gemfile requires is less than the rake version activated, and you do not want to update rake, then you can as well run the command below to remove the version of rake that is activated:
gem list rake
gem uninstall rake
and then select the version of rake you want to uninstall.
That's all.
I hope this helps

running rake fails with Gem::GemNotFoundException ERR

Backstory:
New to rails and attempting to install Passenger on a Mediatemple DV server. I am following and somewhat modifying this CentOS guide here since MT currently does not have any recommended 'how tos' regarding setting up a Rails production environment http://www.freshblurbs.com/installing-ruby-rails-3-centos-nginx.
I have fresh-ly installed gem and then ran gem install rake as root. Now, anytime I try to run
rake some_task
I get the following error
/usr/local/lib/ruby/site_ruby/1.9.1/rubygems.rb:370:in `bin_path':
can't find gem rake ([">= 0"]) with executable rake (Gem::GemNotFoundException)
from /usr/local/bin/rake:19:in `<main>'
rake is installed here /usr/local/bin/rake
$PATH is /usr/kerberos/sbin:/usr/kerberos/bin://sbin://bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:/usr/bin:/usr/local/bin:/root/bin:/usr/bin:/usr/local/lib
output of gem which rake is /usr/local/lib/ruby/1.9.1/rake.rb
... and unfortunately that's about all I got up my sleeves. What am I missing that's causing this to bomb?
Thanks in advance!
I have the similar problem with rake, but in ruby 1.9.2.
http://betterlogic.com/roger/2010/11/ruby-1-9-2-rake-woe/
Maybe in your case it will be helpful too.
Not sure this'll help maybe it will.. maybe not..
But run a gem list first and make sure both rake and also the passenger gem show up. I think I remember seeing a similar error that was misleading trying to setup a production server recently when running:
passenger-install-apache2-module
face palmed when I realised i hadn't installed the passenger gem yet

Resources