Search code examples
mysqlruby-on-railsrubyrake

Why do rake database tasks behave strange when dropping and creating a database?


I use rake to drop the development database using

rake db:drop

It actually deletes the database but it also complains about not knowing the database:

Unknown database 'my_development'
/Users/memyselfandi/.rvm/gems/ruby-1.9.3-p429/gems/mysql2-0.3.14/lib/mysql2/client.rb:67:in `connect'
/Users/memyselfandi/.rvm/gems/ruby-1.9.3-p429/gems/mysql2-0.3.14/lib/mysql2/client.rb:67:in `initialize'
/Users/memyselfandi/.rvm/gems/ruby-1.9.3-p429/gems/activerecord-4.0.1/lib/active_record/connection_adapters/mysql2_adapter.rb:18:in `new'
....
/Users/memyselfandi/.rvm/gems/ruby-1.9.3-p429/bin/rake:23:in `<main>'
Couldn't drop my_development

This is strange because the is database does not exist anymore at this time.

Creating the database using

rake db:create

behaves equally strange

my_development already exists

But it didn't exist before executing rake db:create. I guess there is something wrong with my project but I don't know where to look.


Solution

  • rake db:create creates your development and test databases. If you have the same name for both of them, you will get these errors.