Tuesday, October 11, 2011

Uninitialized MySQL Constant Fix For Rails 3

If you’re doing local Rails development and are attempting to setup a database using MySQL (specifically, MySQL2) and you keep getting:

rake aborted!
uninitialized constant Mysql2

Here’s the fix to the problem:

From within the directory of your application, issue:

$ gem uninstall mysql2
$ gem install mysql2 

This will make sure that you’re running the most recent version of the gem.

Next, update your Gemfile. Comment out the default SQLite reference and add a line for MySQL:

#gem 'sqlite3'
#gem 'mysql2'

Save the file and finally, rake your database:

$ rake db:create

And that should take care of it.


No comments:

Post a Comment