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)
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)
To drop database
rake db:drop
Then for creating database
rake db:create
For migrations
rake db:migrate
For seed
rake db:seed
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.