try this:
change_column :affiliate_payments, :amount, :decimal, :precision => 8, :scale => 2
This will become BigDecimal
Domanda
I am using Rails 3.2.3, and MySQL for my database
I have created a model affiliate_payment.rb, with a column :amount
, initially with datatype float
. I tried to change this to a decimal with the following migration:
class ChangeAffiliateIdAmountToDecimal < ActiveRecord::Migration
def up
change_column :affiliate_payments, :amount, :decimal
end
def down
change_column :affiliate_payments, :amount, :float
end
end
Ran rake db:migrate
...
But when I check the column type to confirm, I find that the column type is now integer
!
2.0.0-p353 :101 > AffiliatePayment.columns_hash["amount"].type
=> :integer
Can someone explain what I am doing wrong?
Soluzione
try this:
change_column :affiliate_payments, :amount, :decimal, :precision => 8, :scale => 2
This will become BigDecimal
Altri suggerimenti
Use this with new ruby syntax:
change_column :affiliate_payments, :amount, :decimal, precision: 8, scale: 2
Hey You have created the migration for change the column type so rake db:migrate
need not be run.
You have to run the migration with there migration number like below
rake db:migrate:up VERSION = version number of migration.