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 ('
Change integer to float column table Rails
Asked Answered
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
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 –
Kynan
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. –
Salcedo You can't use rails code (change_column
) in your terminal.
What you need to do is first create the migration: rails generate migration ChangeMarkUpType
and then put your rails code in the file that was created.
You can read more about migrations here
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 –
Quark
did you run rake db:migrate? –
Adlei
@NeilMurphy Did you see the migration run? Can you update your question with the code in the migration file? –
Saintebeuve
© 2022 - 2024 — McMap. All rights reserved.