要将多个列添加到一个表中,请field:type在使用rails generate migration命令时用空格分隔成对。
通用语法为:
rails generate migration NAME [field[:type][:index] field[:type][:index]] [options]
例如,下面将增加name,salary并且email字段的users表:
rails generate migration AddDetailsToUsers name:string salary:decimal email:string
这将产生以下迁移:
class AddDetailsToUsers < ActiveRecord::Migration[5.0] def change add_column :users, :name, :string add_column :users, :salary, :decimal add_column :users, :email, :string end end