Ruby-on-rails: deleting all data from a table
During development, you might find yourself needing to delete everything from a specific database table to refresh your data. You could drop the whole database and bring it back up again with rake:db:drop, rake:db:setup
, but that’s slow and indiscriminate.
Instead, boot up a console and call delete_all
on your model:
% rails c
> Advisory.count
# => 510
> Advisory.delete_all
# => 510
> Advisory.count
# => 0
I’ve been using this quite a bit while working on an idea related to security.dxw.com – more on that soon.