我正在尝试向现有 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:参数数量错误(3..4 为 5)”
“别担心”,我想,“我会合并论点!”:
add_column :table, :column, :decimal, {:precision => 10, :scale => 6, :after => :existing_column}
但是随后列出现在表格的末尾。我做错了什么?
谢谢:)
最佳答案
你最后的定义是正确的。但这里的问题不在于 Rails,而在于 PostgreSQL,它不允许在特定位置添加列。阅读更多:How can I specify the position for a new column in PostgreSQL?
关于ruby-on-rails - PostgreSQL:在 Rails 迁移中使用 add_column "after"选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27214251/