How to reset a single table in rails?

A lot of people (like me) come here to find how to delete all the data in the table. Here you go:

$ rails console

> ModelName.delete_all

or

> ModelName.destroy_all

destroy_all checks dependencies and callbacks, and takes a little longer. delete_all is a straight SQL query.

More info here: http://apidock.com/rails/ActiveRecord/Base/delete_all/class


I've been using the following from rails console to delete everything in the table and then reset the index counter (Ruby 2 & Rails 4):

> ModelName.delete_all
> ActiveRecord::Base.connection.reset_pk_sequence!('plural_model_name')

To reset the index/primary key in SQLite just type:

$ rails console
> ActiveRecord::Base.connection.execute("DELETE from sqlite_sequence where name = 'yourtablename'")