【发布时间】:2015-06-27 22:44:55
【问题描述】:
我通过 ActiveAdmin (http://activeadmin.info/) 上传了 100 多个具有以下属性的食谱:
class CreateRecipes < ActiveRecord::Migration
def change
create_table :recipes do |t|
t.string :title
t.string :description
t.string :ingredients
t.string :position
t.timestamps
end
end
end
我需要将位置从字符串更改为整数。我可以通过以下方式做到这一点:
change_column :table_name, :column_name, :integer
stackoverflow:Rails migration for change column
问题是我不知道如何返回并重新为所有配方分配一个位置(现在它是一个整数)。我基本上想从 0 开始一直到 100。如果我创建一个新配方,它会自动具有 101 的位置值。
有没有办法在不返回并单独更改每个配方的情况下做到这一点?
【问题讨论】: