Right now my approach is to list every table one at a time and call .delete_all
on it. Which is repetitive:
Example:
#app/db/seeds.rb
Blog.delete_all
Person.delete_all
Post.delete_all
User.delete_all
Author.delete_all
Book.delete_all
# ... on and on for all the tables
And then of course run rake db:seed
which would clear out all the records for those above tables.
Is there a command that does exactly what I want:
Or, is there a way to iterate through all my tables and .delete_all
on each table?
Is there a command that does exactly what I want: deletes all the records from all the tables?
bundle exec rake db:reset
This is functionally equivalent to rake db:drop db:setup
.
Don't want delete the tables?
#app/db/seeds.rb
[Blog, Person, Post, User, Author, Book].each do |table|
ActiveRecord::Base.connection.execute("TRUNCATE #{table.table_name}")
end
SQL-TRUNCATE
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With