【问题标题】:PostgreSQL: add_column "after" option usage in Rails migrationPostgreSQL:在 Rails 迁移中使用 add_column "after" 选项
【发布时间】:2015-01-28 14:58:08
【问题描述】:

我正在尝试在现有 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}

但随后列出现在表格的末尾。我做错了什么?

谢谢:)

【问题讨论】:

  • 是的,我知道这一点,但从理智的角度来看,我有点喜欢将相关的东西放在一起......
  • add_column 方法中没有这样的选项:after => :existing_column。您可以在 documentation for this method 中找到允许的选项
  • @Зелёный 有这样的选项。我在带有 MySQL 的 Rails 3.1 项目中使用了它,它运行良好。
  • @RustamA.Gasanov 请向我展示此选项的文档。

标签: ruby-on-rails postgresql hash database-migration


【解决方案1】:

你最后的定义是正确的。但是这里的问题不在于 Rails,而在于 PostgreSQL,它不允许在特定位置添加列。阅读更多:How can I specify the position for a new column in PostgreSQL?

【讨论】:

  • 啊,我真傻,自从从 MYSQL 迁移到 Postgres 后,我没有测试 :after 选项。很好,谢谢:)
猜你喜欢
  • 1970-01-01
  • 2014-03-24
  • 2013-09-18
  • 2023-03-03
  • 2015-08-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-12-30
相关资源
最近更新 更多