我正在尝试从数据库中的十进制(PostgreSQL NUMERIC
)字段中删除precision和scale属性?
字段:
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
答案 0 :(得分:60)
格式:
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
答案 1 :(得分:0)
在迁移文件中,将字段更改为:integer 并运行 运行rake db:migrate