Saturday, August 13, 2016

How to delete all data and recreate a database tables in Rails?

You can drop the database by:

rake db:drop
This will delete the database.

You can create the database by:

rake db:create
You can create all the tables in the database by:

rake db:migrate
You can combine all three commands database by:

rake db:drop db:create db:migrate
You can accomplish it with just one rake task by:

rake db:schema:load
This loads the schema.rb file into the database.

This rake task is dangerous. It is useful only in development environment only. Do not run in any other environment other than development.

No comments:

Post a Comment