官网链接: Active Record Migrations --- Ruby on Rails Guides
添加string字段
ruby
rails g migration AddFieldIdToTables field_id:string
添加boolean(tinyint)字段
ruby
rails g migration AddFieldFlagToTables field_flag:boolean
添加text字段
ruby
rails g migration AddFieldJsonToTables field_json:text
添加Integer字段
ruby
rails g migration AddFieldDaysToTables field_days:integer
删除string 字段
ruby
rails g migration RemoveEmailFromTables email:string
重命名Text字段为Integer(不建议修改数据类型,耗时较长,建议删除再新建)
ruby
rails g migration RenameFieldFromTables
ruby
class RenameFieldFromTables < ActiveRecord::Migration[5.2]
def change
rename_column :tables, :field, :field_id
change_column :tables, :field_id, :integer
end
end
好了之后不用忘记运行:
ruby
rake db:migrate