# Custom db rake task gives 'development database not configured'

**URL:** <https://www.ruby-forum.com/t/custom-db-rake-task-gives-development-database-not-configured/187600>\
**Category:** Rails\
**Created:** [April 26, 2010, 5:36pm UTC](https://www.ruby-forum.com/t/custom-db-rake-task-gives-development-database-not-configured/187600 "2010-04-26T17:36:38Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![David\_van\_Geest](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/43a26b/32.png) [@David\_van\_Geest](https://www.ruby-forum.com/u/David_van_Geest)\
**Post date:** [April 26, 2010, 5:36pm UTC](https://www.ruby-forum.com/t/custom-db-rake-task-gives-development-database-not-configured/187600/1 "2010-04-26T17:36:38Z")

</div>

Hi all,  
I’m trying to write a simple custom rake task to easily delete some  
database records. However when I run it, I get an error ‘development  
database is not configured’.

Here’s the code:  
lib/tasks/custom.rake

require ‘activerecord’

namespace :db do  
task :delete\_sessions do  
sessions = ENV[‘sessions’].split(’,’).collect! {|n| n.to\_i}  
ActiveRecord::Base.establish\_connection(RAILS\_ENV.to\_sym)  
for session in sessions do  
ActiveRecord::Base.connection.execute(“DELETE FROM pool\_sessions  
WHERE pool\_session\_id=#{session};”)  
end  
end  
end

And how I call it:

$ rake db:delete\_sessions sessions=1,2  
(in )  
rake aborted!  
development database is not configured

(See full trace by running task with --trace)

If I change RAILS\_ENV to test or production I get parallel results.

I can still do other rake db tasks, such as drop, create, and migrate,  
so I know that my config/database.yml is OK.

Any ideas? Thanks.  
-David

–  
David van Geest  
Software Engineer  
Spindance, Inc.  
616.355.7000 x113

---

<div class="post-metadata">

**Author:** ![David\_van\_Geest](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/43a26b/32.png) [@David\_van\_Geest](https://www.ruby-forum.com/u/David_van_Geest)\
**Post date:** [April 26, 2010, 6:46pm UTC](https://www.ruby-forum.com/t/custom-db-rake-task-gives-development-database-not-configured/187600/2 "2010-04-26T18:46:18Z")

</div>

On Apr 26, 4:34 pm, David van Geest [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I can still do other rake db tasks, such as drop, create, and migrate,  
> so I know that my config/database.yml is OK.
> 
> Any ideas? Thanks.

Taking a look at databases.rake in rails itself, I think you want to  
depend on the :load\_config task so that your database.yml file is  
actually loaded

Fred

---

<div class="post-metadata">

**Author:** ![David\_van\_Geest](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/43a26b/32.png) [@David\_van\_Geest](https://www.ruby-forum.com/u/David_van_Geest)\
**Post date:** [April 26, 2010, 11:49pm UTC](https://www.ruby-forum.com/t/custom-db-rake-task-gives-development-database-not-configured/187600/3 "2010-04-26T23:49:00Z")

</div>

Frederick C. wrote:

> actually loaded
> 
> Fred

That’s the ticket. Thanks!

* * *

David van Geest  
Software Engineer  
Spindance, Inc.  
616.355.7000 x113
