【发布时间】:2014-08-17 18:18:07
【问题描述】:
我像这样更改了数据库中的一列:
class ChangeTestTypeInScores < ActiveRecord::Migration
def self.up
change_column :scores, :test_type, :boolean
end
def self.down
change_column :scores, :test_type, :string
end
end
它工作正常,但是当我推送到 heroku 和 Heroku 运行 rake db: migrate 时,我收到以下错误:
PG::DatatypeMismatch: ERROR: column "test_type" cannot be cast automatically to type boolean
HINT: Specify a USING expression to perform the conversion.
: ALTER TABLE "scores" ALTER COLUMN "test_type" TYPE boolean
rake aborted!
StandardError: An error has occurred, this and all later migrations canceled:
既然我已经更新了本地数据库,我该如何解决这个问题?
【问题讨论】:
-
change_column :scores, :test_type, 'boolean USING CAST(column_name AS boolean)' -
所以我修改了我在 rails 中的迁移以匹配你上面的内容,然后重新运行 rake db:migrate?
-
是的。另一种选择是简单地 rake db:drop 和 rake db:migrate(没有我推荐的行)。我想问题是,在 Heroku 上你已经有了一些 test_type 的值,而且它们的类型不能改变。
标签: ruby-on-rails database heroku