1

スキーマにはこれがあります:

 add_index "key_performance_indicators", ["organization_id"], :name => "index_key_performance_inds_on_organization_id"

そして、このインデックスを削除するためにremove_index移行を記述したいのですが、使用する必要のあるインデックス名がわかりません。それkey_performance_indsですかperformance_inds_on_organization_id?または、他の何か?

ビジュアル管理ツールを使用すると、次のように表示されます。

ここに画像の説明を入力してください

4

2 に答える 2

4

:nameオプションをに渡したadd_indexので、インデックスの名前は設定したものになります。index_key_performance_inds_on_organization_idしたがって、この場合は削除します。

remove_index 'key_performance_indicators', :name => 'index_key_performance_inds_on_organization_id'

于 2013-02-13T20:28:09.743 に答える
2

:nameTomdarknessは正しい答えを提供しましたが、特定のデータベーススキーマに準拠する必要がない限り 、その部分を完全に省略したい場合があります。add_indexデフォルトで適切なインデックス名を選択し、remove_index同じデフォルトを使用します。

例えば:

add_index :key_performance_indicators, :organization_id

上記の行はその名前のインデックスを追加しindex_key_performance_indicators_on_organization_id、次の行はそれを削除します:

remove_index :key_performance_indicators, :organization_id
于 2013-02-13T20:44:56.587 に答える