I built a model using rails g model name:string, description:text, price:float, and finished my project, but now want to add more parameters to the model. Instead of starting over, how can I add more parameters? Is there a method to do so within the rails console?
Asked
Active
Viewed 1,846 times
1 Answers
2
rails generate migration AddColumnToTable column:datatype
so if you wanted to add a name
column to a people
table it might look like:
rails generate migration AddNameToPeople name:string
then run rake db:migrate
-
2Sometimes if I forget a column I'll rake db:rollback which rolls back 1 migration, then I'll update the migration file in the db directory, save the file, then rake db:migrate – dtakeshta Aug 20 '16 at 02:06
-
I agree do a rollback, no reason to add a bunch of migration files in the beginning of a project. Hard to keep your migrations clean just to add one column – Oscar Vazquez Aug 20 '16 at 05:11