Gregg Horton Gregg Horton - 1 month ago 7
Ruby Question

Adding a column before another one in Rails

I'm looking to put a column at the front of my table I know you can do

add_column :customer, :first_name, after: :last_name


but is there a way to do
:before
?

Answer

You're able to insert a column at the front of your table by using the :first option:

add_column :table_name, :column_name, :column_type, first: true

You can still use :after to handle all other positioning cases.