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 ?
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 initalizers
Either 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
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.
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…
If not, it’s an interesting video anyway
-philip
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.