0

If I understand correctly, if I run:

rm deveopment.sqlite3 schema.rb

It will delete the database file and the schema files and then I re-create the rake db migrate file but would I have to delete the whole blog and start from scratch or will these commands let me keep the blog structure files loaded and just recreate the database? Not sure which option is the best.

Andrew Marshall
  • 95,083
  • 20
  • 220
  • 214
user3533000
  • 79
  • 1
  • 3
  • 2
    See: [`Resetting the Database`](http://guides.rubyonrails.org/migrations.html#resetting-the-database), if you're looking to start without any data! – vee Apr 15 '14 at 01:54

1 Answers1

0

The .sqlite3 file is the actual DataBase in a SQLite installation.

The schema.rb file is a point-in-time representation of the database structure. This means that every time you alter the structure of a database (add a table, remove a table, add a field to a table, add or remove an index etc.) this file will be changed by rake to reflect the current structure of the database. Note that no data is in that file.

If you erase the database (and the schema.rb file for that matter) a

rake db:setup

would actually execute the following three rake commands:

rake db:create

rake db:migrate

rake db:seed

So if you have your migrations intact and your seed file intact, erasing the schema.rb and the *.sqlite3 files will erase that database (and all its data) and the reflect of the current database schema, but not the migration files or the seed data. You will be able to regenerate the database (with only the seed data, no other data) with a

rake db:setup

Take note that the development.sqlite3 is one of the 3 different databases that might exist, others being production and test.

But, if you are willing to reset the base, a better approach would be a

rake db:reset

Please read Migrations Guide if you need more information about it.

Community
  • 1
  • 1
Marco Poli
  • 513
  • 3
  • 10
  • Thank you. This make sense. So if I understand correctly, I would run rake db: reset and then build the scaffold and the migrate files all over again. correct? – user3533000 Apr 16 '14 at 17:09
  • Not really. All your models and controllers and views that scaffold creates are untouched by a database reset. You should not run scaffold again. If what you want is to undo a scaffold, this is not the way to go. – Marco Poli Apr 16 '14 at 22:29
  • If undoing a scaffold is you you want (this will erase all the data in the database for the model in question, remove all the app files, assets, etc) check [this question](http://stackoverflow.com/questions/963420/undo-scaffolding-in-rails). – Marco Poli Apr 16 '14 at 22:43
  • Thank you. I tried to rollback and destroy the scaffold but it didn't work so i just deleted the whole blog and started again from scratch and got it working correctly. Appreciate your help. – user3533000 Apr 17 '14 at 04:23