How to delete all data from all tables in Rails?
rake db:reset
It recreates your table from migrations.
As suggested in the comments, a faster way to do it (but you have to add a new rake task) is:
namespace :db do
desc "Truncate all tables"
task :truncate => :environment do
conn = ActiveRecord::Base.connection
tables = conn.execute("show tables").map { |r| r[0] }
tables.delete "schema_migrations"
tables.each { |t| conn.execute("TRUNCATE #{t}") }
end
end
Response copied from: answer on SO.
You can have finer control with:
rake db:drop:all
And then create the database without running the migrations,
rake db:create:all
Then run all your migrations,
rake db:migrate
You can also do:
mysqladmin drop databasename