Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8628043
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T08:26:06+00:00 2026-06-12T08:26:06+00:00

I would like to have a rake task for truncating all the tables. I

  • 0

I would like to have a rake task for truncating all the tables. I have found one on the internet, but it is supposed only for Rails 2 and does not work for Rails 3 (problem is in getting a database connection).

rake db:reset is not an option, because I am using PostgreSQL and it also drops the user. Therefore migration fails. I only want to clear the data.

Do you guys have somehting for me?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T08:26:08+00:00Added an answer on June 12, 2026 at 8:26 am

    I’ve found this via google, and then I got a much simpler solution than the one approved, so here it is: Use the database_cleaner gem. Here’re the steps.

    In your Gemfile (execute bundle after modifying):

    gem 'database_cleaner' # you might want to limit this to the dev and staging group
    

    With that gem in place, the statement DatabaseCleaner.clean_with :truncation will truncate the database. Adding it to a rake task is trivial:

    # tasks/db/clean.rake
    
    namespace :db do
    
      desc "Truncate all existing data"
      task :truncate => "db:load_config" do
        DatabaseCleaner.clean_with :truncation
      end
    
    end
    

    That’s it. You can also use the DatabaseCleaner.clean_with :truncation line inside your db/seeds.rb file directly so that you don’t forget to truncate the database before seeding.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a rake task which runs mailman under the rails environment. I'd like
I would like to define a Ruby (1.9.2)-on-Rails(3.0.5) rake task which adds a user
I would like to have an AppWidget that designed like this one . Image:
I've got a photo_albums controller but would like all my actions in that controller
So I have a rake file like the following: require 'fileutils' task :copy do
I would like to implement a Rake task that automates some of the tasks
I have a rake task that looks like so (crontab): cd /data/TheApp/current && bundle
(I'm not using Rails) I have a rake task that sets the environment that
I have a couple simple rake tasks hosted at github that I would like
I have a rake task that populates some initial data in my rails app.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.