How to reposition a new column in rails 3.x migration

I created a hyphen that just adds a new column, but I want it to be added before the created_at and updated_at columns, is there any way to indicate at what position the new column is being created?

I searched and only found someone to say to use the: after option in add_column but does nothing. then I looked in the rails api docs and did not find such an option.

+4
source share
2 answers

After the option works well for me

add_column :table_name, :column_name, :type, :after => :column_name 

Also see this question .

+5
source

From my research, the option :after does not work for SQLite or Postgres , since these DBMSs do not allow such an operation. However, this option works for MySQL .

Literature:

+2
source

Source: https://habr.com/ru/post/1393516/


All Articles