I''ve just cloned my rails app onto another PC, and I''m having a problem getting the database set up. I''ve tried rake db:migrate, then db:create and also db:reset, but I keep getting an SQLException "no such table". It seems this is due to a line in an initializer which accesses one of my tables. Why do the db:* tasks run the initializers ? Do I need to move any db code out of initalizers - if so, where to ? -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Wednesday, July 20, 2011 5:00:45 PM UTC-6, sreid wrote:> > I''ve just cloned my rails app onto another PC, and I''m having a > problem getting the database set up. > > I''ve tried rake db:migrate, then db:create and also db:reset, but I > keep getting an SQLException "no such table". It seems this is due to > a line in an initializer which accesses one of my tables. > > Why do the db:* tasks run the initializers?I''m guessing because it was easier to implement this way. All task implementations can be simply assuming that the full rails environment is available.> Do I need to move any db > code out of initalizersEither that or write said initializers so they can fail gracefully in the event the database (or tables therein) isn''t/aren''t setup.> - if so, where to?Whatever code path eventually "queries" whatever data/settings/state you set/configure from your database can use memoization: def my_settings_from_database @my_settings_from_database ||= load_my_settings_from_database end private load_my_settings_from_database # your initializer code end -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/vbL6wbCuf3UJ. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 21 July 2011 00:00, sreid <sandy-QqoMRuB2QvA51pO8USHC0gC/G2K4zDHf@public.gmane.org> wrote:> I''ve just cloned my rails app onto another PC, and I''m having a > problem getting the database set up. > > I''ve tried rake db:migrate, then db:create and also db:reset, but I > keep getting an SQLException "no such table". It seems this is due to > a line in an initializer which accesses one of my tables. > > Why do the db:* tasks run the initializers ? Do I need to move any db > code out of initalizers - if so, where to ?To get you out of the hole I imagine if you manually create the db (empty) then you will probably be ok. Colin -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Thanks for the suggestions. I ended up using the method described here : http://stackoverflow.com/questions/3485059/running-rake-dbmigrate-without-some-initializers -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
> I''ve just cloned my rails app onto another PC, and I''m having a > problem getting the database set up. > > I''ve tried rake db:migrate, then db:create and also db:reset, but I > keep getting an SQLException "no such table". It seems this is due to > a line in an initializer which accesses one of my tables. > > Why do the db:* tasks run the initializers ? Do I need to move any db > code out of initalizers - if so, where to ?This may be helpful... in helping get your initializer code to run "later" so to speak... http://www.bigbinary.com/videos/2-how-rails-boots If not, it''s an interesting video anyway :) -philip -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.