Rails:如何将add_index添加到现有表 [英] Rails: How to add add_index to existing table
本文介绍了Rails:如何将add_index添加到现有表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经迁移了一个名为units的表,其中有几列。我想知道如何使用cmd将独立的add_index迁移到此表中。这段代码是否正确:
I already migrated a table called units with several columns. I was wondering how to migrate in a stand alone 'add_index' to this table using the cmd. Is this code correct:
class AddIndexToUnits < ActiveRecord::Migration
def self.up
add_index :units, :lesson_id
end
def self.down
remove :units
end
end
我感觉self.down可能是错的,我不确定。
I have a feeling the self.down could be wrong, I am unsure.
推荐答案
self.up方法是正确的。用于你的self.down:
The self.up method is correct. Use this for your self.down:
remove_index :units, :column => :lesson_id
这篇关于Rails:如何将add_index添加到现有表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文