2012-06-26 31 views
2

此问题的答案https://stackoverflow.com/a/973785/1297371问题:How to set Sqlite3 to be case insensitive when string comparing? 讲述如何使用“COLLATE NOCASE”列创建表。如何在迁移表中创建“collat​​e nocase”列?

我的问题是如何在rails迁移中创建这样的列? 即如何从

create table Test 
(
    Text_Value text collate nocase 
); 

create index Test_Text_Value_Index 
    on Test (Text_Value collate nocase); 

做:

create_table :tests do 
    #WHAT HERE? 
end 
add_index #... WHAT HERE? 

回答

0

我添加新的迁移,我删除并重新创建索引,如:

class AddIndexToWordVariations < ActiveRecord::Migration 

    def change 

    remove_index :word_variations, :variation_word 

    add_index :word_variations, :variation_word, :COLLATE => :NOCASE 

    end 

end 

其中 'word_variations' 是我的表

+0

大概这不是在sqlite3上(至少在2013年没有回来),只为人们搜索:http://stackoverflow.com/questions/37878967/sqlite3-on-rails-create-table-using -collat​​e-NOCASE –

0

对于搜索的人,如果'collat​​e'在您的rails版本中仍然不可用(你会得到“未知键:分页”),那么你必须手动创建索引:

execute("create index Test_Text_Value_Index on Test (Text_Value collate nocase);") 

你在“向上变形点焊”(以下简称“drop_table”将删除索引,以及在你的“高清')

相关问题