Rake aborted! Unknown database

(This is a boring technical post, but useful if anyone else Googles the same issue)

While trying out an upgrade of Talks.cam to Rails 2.2, I happened to perform a RAILS_ENV=test rake db:drop

I was a little concerned, then, that every rake task, including RAILS_ENV=test rake db:create then complained Rake aborted! Unknown database talks2_testing.

It turns out that the issue is that within config/environments/test.rb, there is the following setting: config.cache_classes = true.  This causes rake to attempt to load all the classes (which involves inspecting the database), even if the task it is performing is creating the tables it needs to inspect.  So, the solution is to turn off class caching during database creation. 

No comments: