我正在尝试在“位置”列之后向现有的Postgres表添加一个新列“纬度”。
使用此语法将列放在正确的位置:
add_column :table, :column, :decimal, :after => :existing_column
使用此语法可确保该字段是正确的数据类型
add_column :table, :column, :decimal, {:precision => 10, :scale => 6}
但是当我尝试将两者结合起来时:
add_column :table, :column, :decimal, {:precision => 10, :scale => 6}, :after => :existing_column
我得到“ArgumentError:错误的参数数量(5为3..4)”
“别担心”,我想,“我只会结合争论!”:
add_column :table, :column, :decimal, {:precision => 10, :scale => 6, :after => :existing_column}
然后列出现在表的末尾。我做错了什么?
谢谢:)
答案 0 :(得分:20)
你的最后定义是正确的。但是这里的问题不在于Rails,而在于PostgreSQL,它不允许在特定位置添加列。阅读更多:How can I specify the position for a new column in PostgreSQL?