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
Share:
11,078
Neil Murphy
Author by

Neil Murphy

Updated on June 13, 2022

Comments

  • Neil Murphy
    Neil Murphy about 2 years

    I need to change t.integer :mark_up to a float How can I do this? I have tried in my terminal rails g migration change_column(:stakes, :mark_up, :float) by keep getting a syntax error near unexpected token ('

  • Neil Murphy
    Neil Murphy over 9 years
    ok 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
    Nate Beers over 9 years
    did you run rake db:migrate?
  • sebkkom
    sebkkom over 9 years
    @NeilMurphy Did you see the migration run? Can you update your question with the code in the migration file?
  • bsvin33t
    bsvin33t over 9 years
    This 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
    maaachine over 8 years
    Be careful with using the change method when a migration really isn't reversible. If you ran rake db:migrate:down, how would it know what type to convert to? Consider defining up and down instead.