Change integer to float column table Rails
11,078
In your terminal:
rails generate migration ChangeMarkUpToFloat
and in the file that is created: db/migrate/2015xxxxxxxxxx/change_mark_up_to_float.rb
edit it to:
class ChangeMarkUpToFloat < ActiveRecord::Migration
def change
change_column :stakes, :mark_up, :float
end
end
and then back in your terminal:
rake db:migrate
Author by
Neil Murphy
Updated on June 13, 2022Comments
-
Neil Murphy about 2 years
I need to change
t.integer :mark_up
to afloat
How can I do this? I have tried in my terminalrails g migration change_column(:stakes, :mark_up, :float)
by keep getting asyntax error near unexpected token ('
-
Neil Murphy over 9 yearsok i did that and defined change as change_column :stake, :mark_up, :float but my schema still shows that :mark_up is an integer
-
Nate Beers over 9 yearsdid you run rake db:migrate?
-
sebkkom over 9 years@NeilMurphy Did you see the migration run? Can you update your question with the code in the migration file?
-
bsvin33t over 9 yearsThis is ok when the app is not in production. When the app is in production, I would recommend following engineyard's guide on zero downtime deployment
-
maaachine over 8 yearsBe careful with using the
change
method when a migration really isn't reversible. If you ranrake db:migrate:down
, how would it know what type to convert to? Consider definingup
anddown
instead.