2012-06-26 58 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」將刪除索引,以及在你的「高清')