Delete everything from all tables (in Activerecord)


Put this code in seed file and run rake db:seed

ActiveRecord::Base.establish_connection
ActiveRecord::Base.connection.tables.each do |table|
# MySQL
ActiveRecord::Base.connection.execute(“TRUNCATE #{table}”)

# SQLite
# ActiveRecord::Base.connection.execute(“DELETE FROM #{table}”)
end

OR

rake db:reset
It recreates your table from migrations
OR

rake db:schema:dump
rake db:schema:load

OR

rake db:drop:all
rake db:create:all

I hope it would help.
Cheers..!!!

Advertisements