【发布时间】:2011-09-08 16:42:38
【问题描述】:
我的数据库中已经有以下两个迁移:
我创建价格时:
class CreatePrices < ActiveRecord::Migration
def self.up
create_table :prices do |t|
t.string :price_name
t.decimal :price
t.date :date
t.timestamps
end
# add_index :prices (not added)
end
def self.down
drop_table :prices
end
end
当我将 user_id 添加到价格时:
class AddUserIdToPrices < ActiveRecord::Migration
def self.up
add_column :prices, :user_id, :integer
end
# add_index :user_id (not added)
end
def self.down
remove_column :prices, :user_id
end
end
有没有办法从命令行将价格和 user_id 添加到索引?我查看了this question,仍然对如何添加索引感到困惑,而我放置“未添加”的部分似乎很容易出错,因为它们是较早的迁移。
我的问题是,为价格和 user_id 添加索引的最佳方式是什么?
感谢您的帮助!
【问题讨论】:
标签: ruby-on-rails