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

Tomdarkness has provided the right answer but you might want to omit the :name part altogether unless there is a need to conform to a specific database schema. add_index will choose a sensible index name by default for you and remove_index will use that same default.

For example:

add_index :key_performance_indicators, :organization_id

The above line will add the index with the name index_key_performance_indicators_on_organization_id and the following will remove it:

remove_index :key_performance_indicators, :organization_id
于 2013-02-13T20:44:56.587 回答