【发布时间】:2014-01-14 19:48:55
【问题描述】:
我最近在 Rails 中使用 migrate 将字符串转换为小数,这在本地运行良好。然后我将我的应用程序推送到 heroku 并收到以下错误:
Running `rake db:migrate` attached to terminal... up, run.9099
== ChangePriceToDecimal: migrating ===========================================
-- change_column(:products, :price, :decimal, {:precision=>8, :scale=>2})
rake aborted!
An error has occurred, this and all later migrations canceled:
PG::Error: ERROR: column "price" cannot be cast automatically to type numeric
HINT: Specify a USING expression to perform the conversion.
: ALTER TABLE "products" ALTER COLUMN "price" TYPE decimal(8,2)
这是我使用的迁移文件:
class ChangePriceToDecimal < ActiveRecord::Migration
def change
change_column :products, :price, :decimal, precision: 8, scale: 2
end
end
知道我能做些什么来解决这个问题吗?
谢谢, T
【问题讨论】:
标签: ruby-on-rails postgresql ruby-on-rails-4