Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby ActiveRecord Basics Introduction to ActiveRecord Overview of ActiveRecord

Using MySql2 gem with ActiveRecord and Rails 4.0.4

Hey everyone Having an issue using ActiveRecord with the 'mysql2' gem. I'm using rails 4.0.4 There are these lines in my config/application.rb

# Pick the frameworks you want: 
require "active_record/railtie"
require "action_controller/railtie"
require "action_mailer/railtie"
require "sprockets/railtie"
# require "rails/test_unit/railtie"

when i try to run 'rails g model user' i get

 invoke  active_record
 /Users/edjasper/.rvm/gems/ruby-2.1.1/gems/railties4.0.4/lib/rails/application/configuration.rb:110:in `database_configuration': Could not load database configuration. No such file - /Users/edjasper/Desktop/associations_challenge_8/config/database.yml (RuntimeError

any advice?

1 Answer

Maciej Czuchnowski
Maciej Czuchnowski
36,441 Points
  1. Do you have this file and can you post its content? /Users/edjasper/Desktop/associations_challenge_8/config/database.yml

  2. Is this Windows, Mac or Linux?

Hey Maciej, thanks for the help!

  1. i dont have a database.yml but I do have an example.database.yml with...
# MySQL.  Versions 4.1 and 5.0 are recommended.

development:
  adapter: mysql2
  encoding: utf8
  database: associations_challenge_development
  pool: 5
  username: root
  password:
  socket: /tmp/mysql.sock

test:
  adapter: mysql2
  encoding: utf8
  database: associations_challenge_test
  pool: 5
  username: root
  password:
  socket: /tmp/mysql.sock
  1. I'm using a Mac.
Maciej Czuchnowski
Maciej Czuchnowski
36,441 Points

OK, so you basically HAVE TO have that file with that exact name and configure your database there. You can rename this example file and make it just database.yml. Then you have to put your username and password that you use for your mysql (root and empty password may work, depends on your configuration; read up on using mysql).

Very important: if you're using Git, add this file to the list of files that are ignored by Git (it's the file named .gitignore in your project folder). The production server will probably configure its own file (e.g. Heroku) and you don't want to share your personal stuff with people on Git ;).