Setup database on new clone

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 ?

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

To get you out of the hole I imagine if you manually create the db (empty) then you will probably be ok.

Colin

Thanks for the suggestions. I ended up using the method described here : ruby on rails - Running rake db:migrate without some initializers - Stack Overflow

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 :slight_smile:

-philip