I'm trying to add a new column, 'latitude', to an existing Postgres table, after the 'location' column.
Using this syntax puts the column in the correct place:
add_column :table, :column, :decimal, :after => :existing_column
And using this syntax ensures that the field is the correct data type
add_column :table, :column, :decimal, {:precision => 10, :scale => 6}
But when I try and combine the two:
add_column :table, :column, :decimal, {:precision => 10, :scale => 6}, :after => :existing_column
I get "ArgumentError: wrong number of arguments (5 for 3..4)"
"Not to worry", I thought, "I'll just combine the arguements!":
add_column :table, :column, :decimal, {:precision => 10, :scale => 6, :after => :existing_column}
But then the columns appear at the end of the table. What am I doing wrong?
Thanks :)
Your last definition is correct. But the problem here isn't with Rails, but with PostgreSQL, which doesn't allow to add a column at specific position. Read more: How can I specify the position for a new column in PostgreSQL?