0

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?

user1780064
  • 47
  • 1
  • 2
  • 11

1 Answers1

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

dskecse
  • 457
  • 6
  • 16
HolyMoly
  • 2,020
  • 3
  • 22
  • 35
  • 2
    Sometimes 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