Ruby on Rails学习笔记 migrate里的一些修改数据库字段的方法

add_column:增加字段

def add_column(table_name, column_name, type, options = {
     })
  at = create_alter_table table_name
  at.add_column(column_name, type, options)
  execute schema_creation.accept at
end

remove_column:删除字段

def remove_column(table_name, column_name, type = nil, options = {
     })
  execute "ALTER TABLE #{quote_table_name(table_name)} #{remove_column_for_alter(table_name, column_name, type, options)}"
end

change_column :修改字段的类型

def change_column(table_name, column_name, type, options = {
     })
  raise NotImplementedError, "change_column is not implemented"
end

rename_column:更改字段的名称

def rename_column(table_name, column_name, new_column_name)
  raise NotImplementedError, "rename_column is not implemented"
end

你可能感兴趣的:(Ruby,on,Rails)