如何创建rails迁移以删除/更改精度并按小数缩放?

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

田野:

 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 ::错误 – 数字字段溢出”

格式:

 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

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