Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Purge or recreate a Ruby on Rails database

I have a dev Ruby on Rails database full of data. I want to delete everything and rebuild the database. I'm thinking of using something like:

rake db:recreate 

Is this possible?

like image 981
AnApprentice Avatar asked Nov 07 '10 01:11

AnApprentice


People also ask

How do I reset a Rails database?

You can use db:reset - for run db:drop and db:setup or db:migrate:reset - which runs db:drop, db:create and db:migrate.


2 Answers

I know two ways to do this:

This will reset your database and reload your current schema with all:

rake db:reset db:migrate 

This will destroy your db and then create it and then migrate your current schema:

rake db:drop db:create db:migrate 

All data will be lost in both scenarios.

like image 96
thenengah Avatar answered Dec 12 '22 08:12

thenengah


On Rails 4, all needed is

$ rake db:schema:load 

That would delete the entire contents on your DB and recreate the schema from your schema.rb file, without having to apply all migrations one by one.

like image 42
Eneko Alonso Avatar answered Dec 12 '22 10:12

Eneko Alonso