Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails 4: Add Multiple Columns to Existing Table

I know how to add one column to an existing table. Now I have to add many columns to an existing table. Is there a shorter way for:

add_col1_col2_col3_col4_.._coln_to_tables col1:integer col2:integer etc... 

Do I have to do the above for ALL the additional columns I have to add?

like image 411
Sylar Avatar asked Mar 03 '15 15:03

Sylar


People also ask

How do you add multiple columns in rails?

command to create new model and table with columns : rails g model ModelName col_name1:string col_name2:integer col_name3:text ... command to add more columns under existing table: rails g migration AddColumnToModelName col_name4:string col_name5:integer ...


1 Answers

No not necessary. You can do

Assuming TableName is user

rails g migration AddColumnsToUser col1:integer col2:integer .. etc. 
like image 155
Shweta Avatar answered Sep 21 '22 14:09

Shweta