Forum: Ruby on Rails Help w/ rake db:migrate error

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Eric M. (Guest)
on 2009-02-21 18:11
(Received via mailing list)
I made a few changes to my migration files, dropped all tables (rake
db:drop:all), and when I went to re-create everything (rake
db:migrate), I get this:

rake db:migrate --trace
(in /Users/Eric/Development/Work/Rails/pcod)
** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
rake aborted!
undefined method `random' for Tidbit(Table doesn't exist):Class
/Library/Ruby/Gems/1.8/gems/activerecord-2.2.2/lib/active_record/
base.rb:1833:in `method_missing_without_paginate'
/Users/Eric/Development/Work/Rails/pcod/vendor/plugins/will_paginate/
lib/will_paginate/finder.rb:167:in `method_missing'
/Users/Eric/Development/Work/Rails/pcod/app/controllers/application.rb:
6
/Library/Ruby/Gems/1.8/gems/activesupport-2.2.2/lib/active_support/
dependencies.rb:382:in `load_without_new_constant_marking'
/Library/Ruby/Gems/1.8/gems/activesupport-2.2.2/lib/active_support/
dependencies.rb:382:in `load_file'
/Library/Ruby/Gems/1.8/gems/activesupport-2.2.2/lib/active_support/
dependencies.rb:521:in `new_constants_in'
/Library/Ruby/Gems/1.8/gems/activesupport-2.2.2/lib/active_support/
dependencies.rb:381:in `load_file'
/Library/Ruby/Gems/1.8/gems/activesupport-2.2.2/lib/active_support/
dependencies.rb:256:in `require_or_load'
/Library/Ruby/Gems/1.8/gems/activesupport-2.2.2/lib/active_support/
dependencies.rb:221:in `depend_on'
/Library/Ruby/Gems/1.8/gems/activesupport-2.2.2/lib/active_support/
dependencies.rb:133:in `require_dependency'
/Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/
dispatcher.rb:18:in `define_dispatcher_callbacks'
/Library/Ruby/Gems/1.8/gems/activesupport-2.2.2/lib/active_support/
callbacks.rb:182:in `call'
/Library/Ruby/Gems/1.8/gems/activesupport-2.2.2/lib/active_support/
callbacks.rb:182:in `evaluate_method'
/Library/Ruby/Gems/1.8/gems/activesupport-2.2.2/lib/active_support/
callbacks.rb:166:in `call'
/Library/Ruby/Gems/1.8/gems/activesupport-2.2.2/lib/active_support/
callbacks.rb:90:in `run'
/Library/Ruby/Gems/1.8/gems/activesupport-2.2.2/lib/active_support/
callbacks.rb:90:in `each'
/Library/Ruby/Gems/1.8/gems/activesupport-2.2.2/lib/active_support/
callbacks.rb:90:in `send'
/Library/Ruby/Gems/1.8/gems/activesupport-2.2.2/lib/active_support/
callbacks.rb:90:in `run'
/Library/Ruby/Gems/1.8/gems/activesupport-2.2.2/lib/active_support/
callbacks.rb:277:in `run_callbacks'
/Library/Ruby/Gems/1.8/gems/rails-2.2.2/lib/initializer.rb:559:in
`send'
/Library/Ruby/Gems/1.8/gems/rails-2.2.2/lib/initializer.rb:559:in
`prepare_dispatcher'
/Library/Ruby/Gems/1.8/gems/rails-2.2.2/lib/initializer.rb:173:in
`process'
/Library/Ruby/Gems/1.8/gems/rails-2.2.2/lib/initializer.rb:112:in
`send'
/Library/Ruby/Gems/1.8/gems/rails-2.2.2/lib/initializer.rb:112:in
`run'
/Users/Eric/Development/Work/Rails/pcod/config/environment.rb:13
/Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in
`gem_original_require'
/Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in `require'
/Library/Ruby/Gems/1.8/gems/activesupport-2.2.2/lib/active_support/
dependencies.rb:153:in `require'
/Library/Ruby/Gems/1.8/gems/activesupport-2.2.2/lib/active_support/
dependencies.rb:521:in `new_constants_in'
/Library/Ruby/Gems/1.8/gems/activesupport-2.2.2/lib/active_support/
dependencies.rb:153:in `require'
/Library/Ruby/Gems/1.8/gems/rails-2.2.2/lib/tasks/misc.rake:3
/Library/Ruby/Gems/1.8/gems/rake-0.8.3/lib/rake.rb:617:in `call'
/Library/Ruby/Gems/1.8/gems/rake-0.8.3/lib/rake.rb:617:in `execute'
/Library/Ruby/Gems/1.8/gems/rake-0.8.3/lib/rake.rb:612:in `each'
/Library/Ruby/Gems/1.8/gems/rake-0.8.3/lib/rake.rb:612:in `execute'
/Library/Ruby/Gems/1.8/gems/rake-0.8.3/lib/rake.rb:578:in
`invoke_with_call_chain'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/
1.8/monitor.rb:242:in `synchronize'
/Library/Ruby/Gems/1.8/gems/rake-0.8.3/lib/rake.rb:571:in
`invoke_with_call_chain'
/Library/Ruby/Gems/1.8/gems/rake-0.8.3/lib/rake.rb:588:in
`invoke_prerequisites'
/Library/Ruby/Gems/1.8/gems/rake-0.8.3/lib/rake.rb:585:in `each'
/Library/Ruby/Gems/1.8/gems/rake-0.8.3/lib/rake.rb:585:in
`invoke_prerequisites'
/Library/Ruby/Gems/1.8/gems/rake-0.8.3/lib/rake.rb:577:in
`invoke_with_call_chain'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/
1.8/monitor.rb:242:in `synchronize'
/Library/Ruby/Gems/1.8/gems/rake-0.8.3/lib/rake.rb:571:in
`invoke_with_call_chain'
/Library/Ruby/Gems/1.8/gems/rake-0.8.3/lib/rake.rb:564:in `invoke'
/Library/Ruby/Gems/1.8/gems/rake-0.8.3/lib/rake.rb:2019:in
`invoke_task'
/Library/Ruby/Gems/1.8/gems/rake-0.8.3/lib/rake.rb:1997:in `top_level'
/Library/Ruby/Gems/1.8/gems/rake-0.8.3/lib/rake.rb:1997:in `each'
/Library/Ruby/Gems/1.8/gems/rake-0.8.3/lib/rake.rb:1997:in `top_level'
/Library/Ruby/Gems/1.8/gems/rake-0.8.3/lib/rake.rb:2036:in
`standard_exception_handling'
/Library/Ruby/Gems/1.8/gems/rake-0.8.3/lib/rake.rb:1991:in `top_level'
/Library/Ruby/Gems/1.8/gems/rake-0.8.3/lib/rake.rb:1970:in `run'
/Library/Ruby/Gems/1.8/gems/rake-0.8.3/lib/rake.rb:2036:in
`standard_exception_handling'
/Library/Ruby/Gems/1.8/gems/rake-0.8.3/lib/rake.rb:1967:in `run'
/Library/Ruby/Gems/1.8/gems/rake-0.8.3/bin/rake:31
/usr/bin/rake:19:in `load'
/usr/bin/rake:19

I took out the "random" function mentioned in the trace because it was
initially complaining about that method referencing a table that
doesn't exist.  Well, of course it doesn't -- I just dropped the
tables.  But the real question is, why is that method being called in
the first place?  Any suggestions on how to resolve this?
Eric M. (Guest)
on 2009-02-21 18:13
(Received via mailing list)
Also, I'm running SQLite3 locally and tried deleting the
development.sqlite3 database manually, as well as the generated
schema.rb file.
Eric M. (Guest)
on 2009-02-21 18:48
(Received via mailing list)
Found my problem.  I had the line $random_tidbit = Tidbit.random in my
application.rb.  This was causing the problem.  I need a way to define
random_tidbit available in my application.rhtml without having to
place instance variables for random_tidbit inside of each controller.
@random_tidbit in application.rb didn't work, so we temporarily went
with a global variable solution.

How should I do this instead?
Matt J. (Guest)
on 2009-02-23 02:06
(Received via mailing list)
What's the goal? Using a global will mean that in production mode,
$random_tidbit
will only ever be set once. Even worse, if you're running a setup with
multiple instances
(pretty much any modern deployment), each one will get a *different*
value. Do you
want the value to be different for each request?

--Matt J.
This topic is locked and can not be replied to.