37

我正在尝试从NUMERIC我的数据库中的十进制(PostgreSQL)字段中删除精度和比例属性?

田野:

t.decimal  "revenue_per_transaction", :precision => 8, :scale => 2
t.decimal  "item_quantity",           :precision => 8, :scale => 2
t.decimal  "goal_conversion",         :precision => 8, :scale => 2
t.decimal  "goal_abandon",            :precision => 8, :scale => 2
t.decimal  "revenue",                 :precision => 8, :scale => 2

我需要在迁移中添加什么来将这些更改为无限规模和精度,或者增加规模?目前我正在达到规模限制并收到如下错误:

ERROR:   numeric field overflow

这是上下文:Heroku 上的“PG::Error - numeric field overflow”

4

2 回答 2

79

格式 :

change_column(table_name, column_name, type, options): Changes the column to a different type using the same parameters as add_column.

首先在你的终端:

rails g migration change_numeric_field_in_my_table

然后在您的迁移文件中:

class ChangeNumbericFieldInMyTable < ActiveRecord::Migration
  def self.up
   change_column :my_table, :revenue_per_transaction, :decimal, :precision => give whatever, :scale => give whatever
  end
end

然后

run rake db:migrate

来源:http ://api.rubyonrails.org/classes/ActiveRecord/Migration.html

于 2012-10-29T04:27:20.110 回答
-1

在您的迁移文件中,将您的字段更改为 :integer 并运行 run rake db:migrate

于 2014-10-11T20:47:31.363 回答