Joe*_*cha 13 postgresql hash ruby-on-rails database-migration
我正在尝试在"位置"列之后向现有的Postgres表添加一个新列"纬度".
使用此语法将列放在正确的位置:
add_column :table, :column, :decimal, :after => :existing_column
Run Code Online (Sandbox Code Playgroud)
使用此语法可确保该字段是正确的数据类型
add_column :table, :column, :decimal, {:precision => 10, :scale => 6}
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试将两者结合起来时:
add_column :table, :column, :decimal, {:precision => 10, :scale => 6}, :after => :existing_column
Run Code Online (Sandbox Code Playgroud)
我得到"ArgumentError:错误的参数数量(5为3..4)"
"不用担心",我想,"我只会把争论结合起来!":
add_column :table, :column, :decimal, {:precision => 10, :scale => 6, :after => :existing_column}
Run Code Online (Sandbox Code Playgroud)
但是这些列出现在表的末尾.我究竟做错了什么?
谢谢 :)
Rus*_*nov 21
你的最后定义是正确的.但问题不在于Rails,而在于PostgreSQL,它不允许在特定位置添加列.阅读更多:如何在PostgreSQL中指定新列的位置?