I'm using Rails 3.0.3 (don't ask) and when I run a migration for table with decimal column and set :default => 0 it's re-setting the column's scale and precision to (10,0).
def self.up
create_table :courses do |t|
t.integer :user_id
t.string :name
t.decimal :distance, :precision => 5, :scale => 2, :default => 0
t.text :notes
t.timestamps
end
end
When I remove the :default=>0 option from the migration the column's scaled and precision are correct: (5,2)
I tried running a change_column migration with only :default =>: 0 set, but the column's scale and precision were re-set to (10,0)
change_column :courses, :distance, :decimal, :default => 0.0
I know I can go into MySQL and correct the precision and scale of the column, but wondering if I'm doing something wrong or if this is a bug?
Google reveals no information so I think I'm doing something wrong.
Best Answer
Try this one:
t.decimal :distance, :precision => 5, :scale => 2, :default => 0.00