2017-07-14 57 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