1

I have a small Ruby on Rails app, and I made a mistake creating a model and so on.

How can I fully delete its database? Not reseting migrations or dropping its tables, but to delete all db related files? (schema.rb, etc)

onebree
  • 1,853
  • 1
  • 17
  • 44
Carlos Pereira
  • 291
  • 2
  • 4
  • 16
  • Possible duplicate of [Destroy/Remove database in Rails](http://stackoverflow.com/questions/17649686/destroy-remove-database-in-rails) – Mike S Nov 23 '15 at 23:36

2 Answers2

3

To drop database

rake db:drop

Then for creating database

rake db:create

For migrations

rake db:migrate

For seed

rake db:seed
1

Deleting these files will not remove the database from your system. You should never delete your schema.rb because it holds the structure of your database. (And not the database records themselves.) If you simply created a new model, Rails does not automatically create a database table (that's what migrations do).

If you still want to drop your entire database (the structure and data), this is the command you need (found when calling rake -T)

rake db:drop  # Drops the database from DATABASE_URL or 
              # config/database.yml for the current RAILS_ENV 
              # (use db:drop:all to drop all databases)

By default, RAILS_ENV is not set. If you called rake db:drop during this state, all databases associated with this app will be dropped. In order to drop, say, only development:

export RAILS_ENV=development
rake db:drop

You can do the same with test and production environments.

onebree
  • 1,853
  • 1
  • 17
  • 44