Ruby on rails 如何创建一个;核对无酶“;迁移中的表中的列?
这个问题的答案是: 说明如何创建具有“COLLATE NOCASE”列的表 我的问题是如何在rails迁移中创建这样的列? i、 e.从何而来Ruby on rails 如何创建一个;核对无酶“;迁移中的表中的列?,ruby-on-rails,sqlite,migration,collation,Ruby On Rails,Sqlite,Migration,Collation,这个问题的答案是: 说明如何创建具有“COLLATE NOCASE”列的表 我的问题是如何在rails迁移中创建这样的列? i、 e.从何而来 create table Test ( Text_Value text collate nocase ); create index Test_Text_Value_Index on Test (Text_Value collate nocase); 做: 我添加了新迁移,删除并重新创建了索引,如下所示: class AddIndexToW
create table Test
(
Text_Value text collate nocase
);
create index Test_Text_Value_Index
on Test (Text_Value collate nocase);
做:
我添加了新迁移,删除并重新创建了索引,如下所示:
class AddIndexToWordVariations < ActiveRecord::Migration
def change
remove_index :word_variations, :variation_word
add_index :word_variations, :variation_word, :COLLATE => :NOCASE
end
end
class addindextowordvariances:NOCASE
结束
结束
其中“word\u variances”是我的表我添加了新的迁移,删除并重新创建了索引,如下所示:
class AddIndexToWordVariations < ActiveRecord::Migration
def change
remove_index :word_variations, :variation_word
add_index :word_variations, :variation_word, :COLLATE => :NOCASE
end
end
class addindextowordvariances:NOCASE
结束
结束
其中“word\u variances”是供人们搜索的我的表格,如果“collate”在您的rails版本中仍然不可用(您将得到“Unknown key::collate”),那么您必须手动创建索引:
execute("create index Test_Text_Value_Index on Test (Text_Value collate nocase);")
在“def up”(drop_table)中(“drop_table”也会在“def down”中删除索引)对于用户搜索,如果“collate”在您的rails版本中仍然不可用(您将获得“Unknown key::collate”),那么您必须手动创建索引:
execute("create index Test_Text_Value_Index on Test (Text_Value collate nocase);")
在“def up”中(“drop_table”也会在“def down”中删除索引)这可能不在sqlite3上(至少不在2013年),仅用于人员搜索:可能不在sqlite3上(至少不在2013年),仅用于人员搜索: