I am working on an existing rails project where I have to add a new tab. Well, I have written all the corresponding models, views and controllers and then changed the schema.rb file to create the new table.
create_table "ryan_indices", :force => true do |t|
t.string "name"
end
create_table "benchmark_indices", :force => true do |t|
t.string "name"
end
This is my partial schema.rb file. The first table was there before. I am just trying to add a similar new table for which I created model, view and controller and also added those create_table statements in schema.rb file. But, when I run rake db:migrate
it does not create the new table. And the schema.rb file goes back to previous state
I mean my changes go away after I run rake db:migrate
command and it shows nothing on the command line screen.
I don't know what I am missing. Could anyone please help?
To edit schema.rb is considered to be bad practice:
...not designed to be edited, they just represent the current state of the database.
For creating a new model (and thus a new db table) call the rails model generator
rails generate model Product name:string
Or: For new fields for an existing model please generate a migration...
rails generate migration AddNameToProducts
... edit it and then run it with "rake db:migrate
"
These tasks are very well described at the official RailsGuides > Migrations