Topic: Help with Rake

Hi there,

I am new to Ruby on Rails and am working through the Lynda Ruby on Rails Essentials course.

I am running Ruby 1.9.2p0, Rails 3.0.9, and Mysql 5.1.5 32bit, on a 32bit Windows Vista Home Premium operating system.

I am trying to get Rake to do a db:migrate.

I have set up the migration files as per course instruction.

When I run rake db:migrate, however, I get the following:

rake aborted!
Mysql::Error: query: not connected: SHOW TABLES

Tasks: TOP => db:migrate
(See full trace by running task with --trace)

Running rake db:migrate --trace provides the following:

** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute db:migrate
rake aborted!
Mysql::Error: query: not connected: SHOW TABLES
C:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.0.9/lib/active_record/connect
ion_adapters/abstract_adapter.rb:207:in `rescue in log'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.0.9/lib/active_record/connect
ion_adapters/abstract_adapter.rb:199:in `log'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.0.9/lib/active_record/connect
ion_adapters/mysql_adapter.rb:289:in `execute'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.0.9/lib/active_record/connect
ion_adapters/mysql_adapter.rb:407:in `tables'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.0.9/lib/active_record/connect
ion_adapters/mysql_adapter.rb:424:in `table_exists?'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.0.9/lib/active_record/connect
ion_adapters/abstract/schema_statements.rb:425:in `initialize_schema_migrations_
table'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.0.9/lib/active_record/migrati
on.rb:489:in `initialize'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.0.9/lib/active_record/migrati
on.rb:435:in `new'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.0.9/lib/active_record/migrati
on.rb:435:in `up'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.0.9/lib/active_record/migrati
on.rb:417:in `migrate'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.0.9/lib/active_record/railtie
s/databases.rake:142:in `block (2 levels) in <top (required)>'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.9.2/lib/rake/task.rb:205:in `call'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.9.2/lib/rake/task.rb:205:in `block in
execute'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.9.2/lib/rake/task.rb:200:in `each'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.9.2/lib/rake/task.rb:200:in `execute'

C:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.9.2/lib/rake/task.rb:158:in `block in
invoke_with_call_chain'
C:/Ruby192/lib/ruby/1.9.1/monitor.rb:201:in `mon_synchronize'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.9.2/lib/rake/task.rb:151:in `invoke_w
ith_call_chain'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.9.2/lib/rake/task.rb:144:in `invoke'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.9.2/lib/rake/application.rb:112:in `i
nvoke_task'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.9.2/lib/rake/application.rb:90:in `bl
ock (2 levels) in top_level'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.9.2/lib/rake/application.rb:90:in `ea
ch'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.9.2/lib/rake/application.rb:90:in `bl
ock in top_level'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.9.2/lib/rake/application.rb:129:in `s
tandard_exception_handling'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.9.2/lib/rake/application.rb:84:in `to
p_level'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.9.2/lib/rake/application.rb:62:in `bl
ock in run'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.9.2/lib/rake/application.rb:129:in `s
tandard_exception_handling'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.9.2/lib/rake/application.rb:59:in `ru
n'
C:/Ruby192/lib/ruby/gems/1.9.1/gems/rake-0.9.2/bin/rake:32:in `<top (required)>'

C:/Ruby192/bin/rake:19:in `load'
C:/Ruby192/bin/rake:19:in `<main>'
Tasks: TOP => db:migrate

Your assistance would be greatly appreciated as I basically cannot proceed any further in my Rails learning if I cannot do something as simple as a Rake command to modify my database!

Re: Help with Rake

Is your database set up?

You need to edit config/database.yml and tell it what database you are using,  the account and password to use, etc.

Joe got a job, on the day shift, at the Utility Muffin Research Kitchen, arrogantly twisting the sterile canvas snout of a fully charged icing anointment utensil.

Re: Help with Rake

Hi,

Yep, I've got config/database.yml set up with account and password. My rails wouldn't run a demo site I'm working on without it so I had to get that straight. I actually removed the database and recreated it from scratch just in case I'd done something wrong or missed a step...but no dice sad

Re: Help with Rake

run your app under the console,  it should give you a better description of what's happening

Joe got a job, on the day shift, at the Utility Muffin Research Kitchen, arrogantly twisting the sterile canvas snout of a fully charged icing anointment utensil.

Re: Help with Rake

I hate to say it, but not sure what you mean by the console. I take it you don't mean the command prompt as that's what I've been using?

Re: Help with Rake

Cd into the directory where your app is located and type

rails console

That will boot the app, and then leave you in console mode,  a command line environment inside your app.

If you have a model in your app called Widget,  you could do this:

W = Widget.find(:first)

And you'll see the results

Joe got a job, on the day shift, at the Utility Muffin Research Kitchen, arrogantly twisting the sterile canvas snout of a fully charged icing anointment utensil.

Re: Help with Rake

Ok, thanks for that. I created a model called widget just for the purpose of the exercise. Entering the command you suggested produced the following:

Loading development environment (Rails 3.0.9)
irb(main):001:0> W = Widget.find(:first)
ActiveRecord::StatementInvalid: Mysql::Error: Table 'simple_cms_development.widg
ets' doesn't exist: SELECT  `widgets`.* FROM `widgets` LIMIT 1
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.0.9/lib/active_r
ecord/connection_adapters/abstract_adapter.rb:207:in `rescue in log'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.0.9/lib/active_r
ecord/connection_adapters/abstract_adapter.rb:199:in `log'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.0.9/lib/active_r
ecord/connection_adapters/mysql_adapter.rb:289:in `execute'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.0.9/lib/active_r
ecord/connection_adapters/mysql_adapter.rb:633:in `select'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.0.9/lib/active_r
ecord/connection_adapters/abstract/database_statements.rb:7:in `select_all'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.0.9/lib/active_r
ecord/connection_adapters/abstract/query_cache.rb:56:in `select_all'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.0.9/lib/active_r
ecord/base.rb:473:in `find_by_sql'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.0.9/lib/active_r
ecord/relation.rb:64:in `to_a'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.0.9/lib/active_r
ecord/relation/finder_methods.rb:341:in `find_first'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.0.9/lib/active_r
ecord/relation/finder_methods.rb:122:in `first'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/activerecord-3.0.9/lib/active_r
ecord/relation/finder_methods.rb:105:in `find'
        from C:in `find'
        from (irb):1
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.9/lib/rails/comman
ds/console.rb:44:in `start'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.9/lib/rails/comman
ds/console.rb:8:in `start'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.9/lib/rails/comman
ds.rb:23:in `<top (required)>'
        from script/rails:6:in `require'
        from script/rails:6:in `<main>'irb(main):002:0>

Re: Help with Rake

post your database.yml,  it looks like it has:

database:simple_cms_development

but that database doesn't exist,  or you manually created a table called widget instead of widgets.

remember that a Model called Widget expects a table called widgets

Joe got a job, on the day shift, at the Utility Muffin Research Kitchen, arrogantly twisting the sterile canvas snout of a fully charged icing anointment utensil.

Re: Help with Rake

Hmm. Went back into mysql but that's definitely the right database. It doesn't have any tables on it however, I guess because rake isn't working...so no db:migrate sad

Re: Help with Rake

Then it must be login id and or password,  is it MySQL?

post your database.yml

Joe got a job, on the day shift, at the Utility Muffin Research Kitchen, arrogantly twisting the sterile canvas snout of a fully charged icing anointment utensil.

11

Re: Help with Rake

Here 'tis!

# MySQL.  Versions 4.1 and 5.0 are recommended.
#
# Install the MySQL driver:
#   gem install mysql2
#
# And be sure to use new-style password hashing:
#   http://dev.mysql.com/doc/refman/5.0/en/old-client.html
development:
  adapter: mysql
  encoding: utf8
  reconnect: false
  database: simple_cms_development
  pool: 5
  username: simple_cms
  password: bugger1
  host: localhost

# 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: mysql
  encoding: utf8
  reconnect: false
  database: simple_cms_test
  pool: 5
  username: simple_cms
  password: bugger1
  host: localhost

production:
  adapter: mysql
  encoding: utf8
  reconnect: false
  database: simple_cms_production
  pool: 5
  username: simple_cms
  password: bugger1
  host: localhost

12

Re: Help with Rake

Say, I tried reinstalling Rails a couple of times and I noticed these error messages came up. could they somehow be related?

Fetching: builder-2.1.2.gem (100%)
WARNING: builder-2.1.2 has an invalid nil value for @cert_chain
Fetching: i18n-0.5.0.gem (100%)
Fetching: activemodel-3.0.10.gem (100%)
Fetching: rack-1.2.3.gem (100%)
Fetching: rack-test-0.5.7.gem (100%)
Fetching: rack-mount-0.6.14.gem (100%)
Fetching: tzinfo-0.3.29.gem (100%)
Fetching: abstract-1.0.0.gem (100%)
WARNING: abstract-1.0.0 has an invalid nil value for @cert_chain

Dreaming of a rake-filled future...

13

Re: Help with Rake

Well...I solved the problem... reinstalling ruby, rails, and mysql in various configurations didn't work so I just set up a dual boot Ubuntu on my computer. Ruby, Rails, etc running perfectly there. So...yeah.