One of our engineers is just getting into Rails development, and he ran into some strange issues getting things working. He had tried in the past, and never quite got all the ducks lined up, so there was a chance that his environment was a bit off.
He could run ‘rake db:create’ and ‘rake db:drop’ with success, but ‘rake db:migrate’ would fail silently. This is a problem we didn’t find easily in Google, so I’m writing this for posterity.
First step, throw ‘–trace’ on the end.
bash$ rake db:migrate --trace
<snip>
** Invoke environment (first_time)
** Execute environment
bash$
That’s odd. So I took a look in the rails gem at the rake files. As suspected, ‘db:drop’ and ‘db:create’ have different prereqs than ‘db:migrate’, which includes “=> :environment” (load the whole Rails environment) in its task definition.
A quick test rakefile added to his project validated the conclusion:
task :noenvtest do puts "*** ohai no env" end task :envtest => :environment do puts "*** ohai env" end
As expected, ‘rake noenvtest’ gave output, and ‘rake envtest’ failed silently again.
So, we took a look at his gems. While he had rails 2.3.8 and friends, his rubygems was at 1.3.4 and his gem sources were out of date. We deleted the old sources (gem source -r http://gems.rubyforge.org) and added the right one. Updated the rest of his gems, and db:migrate runs again!