Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add several columns to a database in Rails

Hi I just created a database in RoR. I now want to add 10 more columns to it. However, I dont want to use the following type of command that adds only 1 column at a time:

rails generate migration AddClosing_Hrs1ToBusinesses closing_hrs1:string

Is there a way to add multiple columns to my database without having to type a command for each column individually like above?

like image 794
banditKing Avatar asked Mar 03 '12 21:03

banditKing


People also ask

How do you add multiple columns in rails?

To add multiple columns to a table, separate field:type pairs with spaces when using rails generate migration command.


1 Answers

You can specify your column names all in one go

rails generate migration AddClosing_Hrs1ToBusinesses closing_hrs1:string new_cloumn:string third_column:string

Documentation : http://guides.rubyonrails.org/migrations.html

like image 90
Anand Shah Avatar answered Nov 09 '22 17:11

Anand Shah