在Rails中添加另一个列之前的列

我想把一根柱放在桌子的前面,我知道你可以做到

add_column :customer, :first_name, after: :last_name 

但有没有办法:before

您可以使用:first选项在表格前面插入一列:

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

您仍然可以使用:after来处理所有其他定位案例。

顺便说一下,这些是特定于mysql的选项。

https://github.com/rails/rails/blob/80e66cc/activerecord/lib/active_record/connection_adapters/mysql/schema_creation.rb#L50-L55列出了可用选项,看起来它们只支持before和之后。

对于它的价值,PostgreSQL仅支持在表的末尾添加列。

相关问题: alter table add …在`code`之前?