2017-07-14 58 views
0

我試圖使這個遷移:添加陣列默認遷移結束 - 軌道

def up 
    change_column :navigation_items, :access, 'text USING CAST(access AS text)', array: true 
end 

但我發現了這個錯誤:

PG::SyntaxError: ERROR: syntax error at or near "[" 
LINE 1: ...ALTER COLUMN "access" TYPE text USING CAST(access AS text)[] 

有誰知道如何使確定該遷移數組設置爲true?

回答

0

的語法應該是

change_column :navigation_items, :access, :text, array: true, default: [] 

假設你想要的默認值的列是[]

+0

這是我第一次嘗試,但我得到這個錯誤:'PG :: DatatypeMismatch:錯誤:列「訪問「不能自動轉換爲鍵入文本[] 提示:您可能需要指定」USING access :: text []「。 – Bitwise

+0

您確定訪問不是PG上的保留字嗎? https://www.postgresql.org/docs/current/static/sql-keywords-appendix.html 它說非PG保留,但我覺得值得重命名它 – neo