Error when loading or migrating database in rails - ruby-on-rails

Whenever I try to use rake db:schema:load or rake db:migrate, I get keep getting the following error:
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
I already have the mysql gem installed which is version 2.8.1. Am I missing something?
database.yml
development:
adapter: mysql
database: db_development
host: localhost
username: root
password: password
encoding: utf8
socket: /Applications/rubystack/mysql/tmp/mysql.sock

Try installing mysql2 gem
sudo gem install mysql2
If you are on Rails 3, add
gem 'mysql2'
to your Gemfile & run
bundle install
And change the adapter to mysql2 in your database.yml. I solved many problems with this, might solve yours too.

Related

Ruby on Rails - could not load postgres adapter

Building a rails app on heroku (locally). Following their tutorials for rails, and installing postgres locally.
When ever I run the server or generate a migration I get the following err:
LoadError (Could not load 'active_record/connection_adapters/posgtres_adapter'. Make sure that the adapter in config/database.yml is valid. If you use an adapter other than 'mysql', 'mysql2', 'postgresql' or 'sqlite3' add the necessary adapter gem to the Gemfile.):
database.yml:
default: &default
adapter: postgresql
encoding: unicode
pool: 5
development:
<<: *default
database: myapp_development
username: Name
password: secret
host: localhost
Gem file has: gem 'rails' '4.2.0', and gem 'pg' installed
my machine's OS: Windows 64x
Any and all help appreciated.
Doubtful this is the same issue you are having but, posting these details in case it gives a lead. I'm using Windows 10
I had the same error message. To troubleshoot, I tried to do a reinstall of pg with 'gem install pg' but a file was locked.
Found I had a process still using one of the PG files and shut down the process, deleted the entire pg directory found at C:\Ruby200-x64\lib\ruby\gems\2.0.0\gems\pg-0.18.3-x64-mingw32
Reran 'gem install pg' rake db:setup, rake db:create, rake db:migrate and the error was gone.

JRuby keeps saying "please install `gem install activerecord-jdbcmysql-adapter"

I am following a simple tutorial and i am using mysql. when i run
jruby -S rake db:create:all
it gives an error message:
Please install the jdbcmysql adapter: `gem install activerecord-jdbcmysql-adapter` (no such file to load -- active_record/connection_adapters/jdbcmysql_adapter)
But I already have this installed. anyone know how to solve this problem? I am using JRuby 1.6.7. (I also have ruby 1.9.3 on my computer, don't know if it matters)
here's my database.yml
development:
adapter: jdbcmysql
database: MyRail2_development
pool: 5
username: root
password: *****
host: localhost
Have you made sure that your Gemfile includes a line that references the adapter gem? e.g.:
platforms :jruby do
gem 'activerecord-jdbc-adapter'
gem 'activerecord-jdbcmysql-adapter'
end
And did you run bundle install, after you updated your GemFile? i.e.:
jruby -S bundle install
It shouldn't matter that you have MRI Ruby 1.9.3 on your machine, as long as you remember to execute the usual Rails tutorial commands prefixed with jruby -S, as you've indicated in your question.

RoR migration mysql2 gem

I'm going through a RoR tutorial, but when I try to run a migration it returns
...
*** About to add an index ***
--add_index("admin_users", "username")
rake aborted!
An error has occurred, all later migrations canceled:
invalid date
Looking around online it seems the problem is with the mysql2 gem and "add_index". How should I fix it? I tried uninstalling the mysql2 gem and changing the database.yml file to use mysql but it returned
"Please install the mysql adapter: 'gem install activerecord-mysql-adapter'"
which it then couldn't find.
I'm using Windows Vista, Rails 3.2.1 and the mysql2 gem is 0.3.11 x86-mingw32 and the mysql gem is 2.8.1 x86-mingw32.
We use mysql, just check if this setup works
in GEM file
gem 'rails', '2.3.2'
gem 'mysql', '2.7'
in database.yml
development:
adapter: mysql
encoding: utf8
reconnect: false
database: <database name>
pool: 5
username: <user name>
password: <password>
host: localhost

"no such file to load -- pg" when trying rake db:create

The symptom of my problem is pretty simple:
$ rake db:create
(in /home/jason/projects/blog)
rake aborted!
no such file to load -- pg
(See full trace by running task with --trace)
I've already successfully run bundle install and gem install pg, so I don't know what else I might need to do.
Here's my `config/database.yml if it helps:
# SQLite version 3.x
# gem install sqlite3-ruby (not necessary on OS X Leopard)
development:
adapter: postgresql
encoding: unicode
database: blog_development
pool: 5
username: blog
password: foo
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
adapter: postgresql
encoding: unicode
database: blog_development
pool: 5
username: blog
password: foo
production:
adapter: sqlite3
database: db/production.sqlite3
pool: 5
timeout: 5000
I figured it out. If I use pg instead of postgresql in my config/database.yml, it works.
Go to console and type below:
vim Gemfile
Inside the file commend the below:
- #gem 'sqlite3-ruby', :require => 'sqlite3'
Inside the file add the below:
- gem 'pg', :require => 'pg'
Problem Solved!!! :-) Enjoy!
One possibility is that the rake binary that you are running is from another ruby/gem environment and that it doesn't have access to the gems that you've installed.
If you have more than one version of ruby installed, try running which gem and then which rake to see if they are being run from the same bin directory. For example, on my machine both binaries are executed from bin directories under the same Ruby install:
/Users/scott/.rvm/rubies/ruby-1.9.2-p136/bin/gem
/Users/scott/.rvm/gems/ruby-1.9.2-p136/bin/rake
If you only have one ruby version installed on your system, then this isn't the answer!

error trying to install Postgres on Windows to use with existing Rails project

I did the following after installing Postgres locally:
gem install postgres-pr
I changed the database.yml:
development:
adapter: postgresql
encoding: unicode
database: typhoon_development
pool: 5
Then, when I did a rake db:create got:
uninitialized constant PostgresPR::Connection::UNIXSocket
Couldn't create database for {"encoding"=>"unicode", "adapter"=>"postgresql", "database"=>"typhoon_development", "p
ool"=>5}
I'm doing it locally to mimic the heroku environment.
Try to provide hostname and port number in the config.
I used a different gem

Resources