Reputation: 468
I am currently working on a ROR project. I had generated the scaffold for Notes and run the migrations for it. However now we had a little change of plans and I want to get the app back to the initial state. So I run rails scaffold destroy notes and so I had all files generated erased. But I still have the file schema.rb with the Notes table migration defined. How do I get rid of it without changing manually this file (which is considered bad practice)? If I generate the Notes model and run the migration is this file going to update and everything will be fine? Or there could be conflicts? I tried to run rake db:reset. It seems to have not worked. But still in the end of the process I got this message.
Couldn't create database for {"adapter"=>"postgresql", "encoding"=>"unicode", "database"=>"thenotesapp", "pool"=>5, "username"=>"thenotesapp", "password"=>"thenotesapp"}
-- enable_extension("plpgsql") -> 0.0367s
-- create_table("notes", {:force=>:cascade}) -> 0.0628s
-- initialize_schema_migrations_table() -> 0.0276s
-- enable_extension("plpgsql") -> 0.0251s
-- create_table("notes", {:force=>:cascade}) -> 0.0157s
-- initialize_schema_migrations_table() -> 0.0012s
schema.rb remains like this scaffold destroyed
ActiveRecord::Schema.define(version: 20150114071920) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
create_table "notes", force: :cascade do |t|
t.string "title"
t.text "text"
t.datetime "created_at"
t.datetime "updated_at"
end
end
Upvotes: 2
Views: 1843
Reputation: 27
First drop the database:
rake db:drop
Then create db:
rake db:create
After that migrate tables:
rake db:migrate
If you want to populate database, then:
rake db:seed
Upvotes: 1
Reputation: 52357
To drop the database you have to firstly set it, as you've said to initial state - to do so run:
rake db:migrate VERSION=0
Next step would be to remove all migration files (/db/migrate
directory) manually.
That's it - you have clean schema.rb
containing no tables.
Upvotes: 2