See the discussion above... This is a Heroku application and it needs a database configured or it is going to try and force Postgres as a dependency to help you out.
heroku run rake db:create fails with Could not find gem 'pg..., but the database is mysql2 (not postgresql)
-
30-06-2023 - |
Question
I receive the following error when I run heroku run rake db:create
:
Running `rake db:create` attached to terminal... up, run.6027
Could not find gem 'pg (>= 0.11.0) ruby' in the gems available on this machine.
Run `bundle install` to install missing gems.
In the config/database.yml I'm using the default mysql2 database:
production:
adapter: mysql2
database: redmine
host: localhost
...
development:
adapter: mysql2
...
test:
adapter: mysql2
...
So I guess 'pg (>= 0.11.0) ruby' does not need to be installed. Am I wrong?
I'm using Windows XP. It is the first time I use Ruby.
UPDATE 1
I forgot to say bundle install
finished correctly without errors.
On the other hand, Gemfile has the following code:
adapters.each do |adapter|
case adapter
when 'mysql2'
gem "mysql2", "~> 0.3.11", :platforms => [:mri, :mingw]
gem "activerecord-jdbcmysql-adapter", :platforms => :jruby
...
when /postgresql/
gem "pg", ">= 0.11.0", :platforms => [:mri, :mingw]
gem "activerecord-jdbcpostgresql-adapter", :platforms => :jruby
...
So again, I guess it should never enter in when /postgresql/
when the command heroku run rake db:create
is executed. Am I right?
Solution
OTHER TIPS
You need to do bundle install before running the rake task for db creation and fulfill all gem dependencies. This is required even though you are using mysql and not postgres because the 'pg gem' is specified in the Gemfile and you have to make sure that all gem dependencies in your Gemfile are made available to your application by running the bundle install commmand.
As in your case you are using mysql, you do not require the 'pg gem' and can remove or comment it in the Gemfile.