【发布时间】:2020-08-06 10:36:13
【问题描述】:
我想将列类型从文本更改为字符串数组,所以我使用此迁移
class ChangeEmailsAndPhonesToArrayOfString < ActiveRecord::Migration[6.0]
def up
change_table :hotels do |t|
t.change :emails, :string, array: true, default: []
t.change :phones, :string, array: true, default: []
end
end
def down
change_table :hotels do |t|
t.change :emails, :text
t.change :phones, :text
end
end
end
但是当我运行 rails db:migrate 时出现此错误
PG::DatatypeMismatch: ERROR: column "emails" cannot be cast to type character varying[] 提示:您可能需要指定“USING emails::character varying[]”。
我该如何解决这个问题?
【问题讨论】:
-
感谢链接非常有用
标签: ruby-on-rails ruby