I am trying to create a database for my rails 5.0.0.1 application with rails db:create but I receive the following error:
Specified 'postgresql' for database adapter, but the gem is not loaded. Add `gem 'pg'` to your Gemfile (and ensure its version is at the minimum required by ActiveRecord).
The point is that there is a gem 'pg' in my Gemfile, which was updated to version 1.0.0 by bundle update, launched after bundle install:
$ gem list
...
pg (1.0.0, 0.20.0)
I have no idea why rails cannot recognize the installed pg gem and fails to create a database for my application.
pg version 1.0.0 work fine with rails 5.1.5 and newer.
See this github post
Related
I'm trying to install the pg_search gem. In the first attempt I did not pay attention to the necessary version of ruby (we are using 2.3.1 and 2.4 was required), in the error message that appeared I was asked to run bundle update, but it updated pg_search to 2.3.5 which require ruby >= 2.5. Even though I specified an older version of the gem, it still shows the same message:
Gem::InstallError: pg_search requires Ruby version >= 2.5.
An error occurred while installing pg_search (2.3.5), and Bundler cannot continue.
Make sure that `gem install pg_search -v '2.3.5'` succeeds before bundling.
I already installed the gem by running docker-compose run web gem install pg_search -v 2.1.4, and recreated the container. My Gemfile:
source 'https://rubygems.org'
gem 'rails', '~> 5.2.0'
# Use sqlite3 as the database for Active Record
# Use Puma as the app server
#gem 'mina-puma', :require => false
gem 'puma', '~> 3.7.1'
gem 'pg', '~> 0.18'
gem 'pg_search', '~> 2.1', '>= 2.1.4'
...
Bundler version: bundler (>= 1.3.0)
I would like to know how to remove pg_search 2.3.5 and install 2.1.4.
Even though I specified an older version of the gem
No, you didn't.
You specified '~> 2.1', '>= 2.1.4', which means anything 2.1.4 <= version < 3.0.0.
By running bundle update, this installed the latest available version that met your requirements, which was apparently 2.3.5, not 2.1.4.
If you need to also specify a constraint to ruby version 2.3.1, you can also put this in the Gemfile:
ruby '2.3.1'
...And then running bundle update will also take that into consideration when finding the latest compatible dependencies.
I would like to know how to remove pg_search 2.3.5 and install 2.1.4
You don't have version 2.3.5 installed against this ruby version, because it's incompatible.
Apparently you've already installed version 2.1.4.
The problem is that your Gemfile.lock is still expecting version 2.3.5. There are a few ways you could resolve this, but one way or another you need to update the Gemfile.lock to have a compatible set of dependencies with your ruby version.
The simplest approach is probably to just re-run bundle update pg_search, but make sure you're actually using the correct ruby version this time. That should downgrade the dependency, as the newer library version isn't compatible with the older ruby version.
If you still encounter issues, you could take my advice of adding the ruby constraint to the Gemfile, and revert whatever other changes you've recently made that created this incompatible mix of dependencies.
When running rails server, I load this warning:
Gem::LoadError: Specified 'sqlite3' for database adapter, but the gem is not loaded. Add `gem 'sqlite3'` to your Gemfile (and ensure its version is at the minimum required by ActiveRecord).
Yet my gemfile has the gem
group :development do
gem 'sqlite3'
What is causing this error?
Using instructions for rails update from here https://edgeguides.rubyonrails.org/upgrading_ruby_on_rails.html#upgrading-from-rails-4-2-to-rails-5-0
Deleted gem sqlite3 ( v 1.4.0 ) and installed it with version 1.3.13 & it worked
gem cleanup sqlite3
And
bundle install
to let Rails choose right version of sqlite3
Have the same problem in AWS cloud9 environment. You need to change your gemfile to read gem 'sqlite3', '~> 1.3.6' then run bundle update. got this from "can't activate sqlite3 (~> 1.3.6), already activated sqlite3-1.4.0"
I am facing a mysql2 gem version error while trying to create a new RailsApps example application using Rails Composer. For example, while creating a rails-devise-roles example with the following command:
$ rails new rails-devise-roles -m https://raw.github.com/RailsApps/rails-composer/master/composer.rb
The error is:
Error loading the 'mysql2' Active Record adapter. Missing a gem it depends on? can't activate mysql2 (< 0.6.0, >= 0.4.4), already activated mysql2-0.3.21. Make sure all dependencies are added to Gemfile. (Gem::LoadError)
The messages on the console indicate mysql2 version 0.3.21 is pulled in
run bundle install --without production from "."
Fetching gem metadata from https://rubygems.org/.........
Fetching gem metadata from https://rubygems.org/.
Resolving dependencies....
...................
Using mysql2 0.3.21
The generated Gemfile has
gem 'mysql2', '~> 0.3.18'
I am using ruby 2.5.3 and Rails 5.2.1
I am not able to run bundle update devise or bundle install
$ bundle update devise
Fetching gem metadata from http://rubygems.org/.............
Fetching gem metadata from http://rubygems.org/..
Resolving dependencies............
Fetching rake 12.3.0 (was 10.1.0)
Installing rake 12.3.0 (was 10.1.0)
Gem::RuntimeRequirementNotMetError: rake requires Ruby version >= 2.0.0. The current ruby version is 1.9.1.
An error occurred while installing rake (12.3.0), and Bundler cannot continue.
Make sure that `gem install rake -v '12.3.0'` succeeds before bundling.
and this is what I am getting on $ bundle install
Fetching gem metadata from http://rubygems.org/.............
Fetching gem metadata from http://rubygems.org/..
You have requested:
devise = 2.2.4
The bundle currently has devise locked at 3.1.0.
Try running `bundle update devise`
If you are updating multiple gems in your Gemfile at once,
try passing them all to `bundle update`
Thanks in advance
From the log trace given it seems like you have specified the version 2.2.4 in gemfile for devise.
Just remove the version from gemfile and then run bundle update, rubygems will itself find the dependent gem version based on the ruby version and lock it the gemfile.lock.
The problem being that your Devise Gem is locked to a particular version which is the problem. If you check your gemfile.lock you will see its fixed.
Changing version in a Gemfile will not affect which gem version is loaded. bundle install / bundle update is actually needed.
Example of how you can go about that is in the Devise Gem documentation.
Change your gemfile to gem 'devise' and run bundle install rubygems will itself find the dependent gem version based on the ruby version and lock it to the gemfile.lock.
Its important to update rails after all of the security fixes, but when I try it says the gem does not exist even though the rails blog says it has been released.
The blog says to upgrade: http://weblog.rubyonrails.org/2013/1/28/Rails-3-0-20-and-2-3-16-have-been-released/
But when I add the following to the Gemfile:
gem 'rails', '3.2.16'
And when I update I get:
➜ bundle update rails (ruby-1.9.3-p374#usertesting-orders)
Fetching gem metadata from http://rubygems.org/......
Fetching gem metadata from http://rubygems.org/..
Could not find gem 'rails (= 3.2.16) ruby' in the gems available on this machine.
Any tips?
UPDATE: there is no such gem. Its supposed to be 3.2.11 NOT 3.2.16. The .16 is for the 2.3 Rails and not the 3.2.
Try gem 'rails', '3.2.11' ,according to the stable branch in GitHub.