Ruby 2.7.3 Rails 6.1.3.1 PG 1.2.3 PostgreSQL 12.7
我正在将一个Rails4应用程序迁移到Rails6的过程中。
现在失败的迁移的原始内容是
change_column :pages, :content, 'jsonb USING CAST(content AS jsonb)', null: false, default: '[]'我试着摆脱演员阵容,就像这样:
change_column :pages, :content, 'jsonb', null: false, default: '[]'然后抛出错误
PG::DatatypeMismatch: ERROR: column "content" cannot be cast automatically to type jsonb
HINT: You might need to specify "USING content::jsonb".如果我将其切换到此样式,它将以与第一个样式相同的方式放大
change_column :pages, :content, 'jsonb USING content::jsonb', null: false, default: '[]'抛出错误
PG::SyntaxError: ERROR: syntax error at or near "USING"
LINE 1: SELECT 'jsonb USING CAST(content AS jsonb)'::regtype::oid
^
CONTEXT: invalid type name "jsonb USING CAST(content AS jsonb)"对这里的正确语法有什么想法吗?
发布于 2021-08-05 13:59:37
你可以尝试在造型的时候使用using (我知道,说使用两次听起来很奇怪!)
change_column :pages, :content, :jsonb, using: "content::JSONB", null: false, default: '[]'看看能不能成功。
https://stackoverflow.com/questions/67944149
复制相似问题