ruby数据库表添加字段、修改字段类型、修改字段名称
3.8 使用 change
方法
1.为表添加字段
rails g migration add_column_to_d_groups_equip_num
class AddColumnToDGroupsEquipNum < ActiveRecord::Migration[5.1] def change add_column :d_groups, :equip_num ,:integer end end
2.修改表字段类型
rails g migration change_column_to_d_groups_equip_num
class ChangeColumnToDGroupsEquipNum < ActiveRecord::Migration[5.1] def change change_column :d_groups, :equip_num, :string end end
3.修改表字段名称
rails g migration change_column_to_d_groups_equip_num_equio_nums
class ChangeColumnToDGroupsEquipNumEquipNums < ActiveRecord::Migration[5.1] def change rename_column :d_groups, :equip_num, :equip_nums end end