繁体   English   中英

n Rails 6,通过迁移向表添加小数列的正确方法是什么?

[英]n Rails 6, what's the proper way to add a decimal column to a table via a migration?

我刚刚升级到 Rails 6.1.4.4,之前在 Rails 4 中通过的迁移在新设置中失败了。 这是

class AddLatLngToStores < ActiveRecord::Migration[4.2]
  def change
    add_column :stores, :lat, :decimal, {:precision=>10, :scale=>6}
    add_column :stores, :lng, :decimal, {:precision=>10, :scale=>6}
  end
end

现在当我运行“rake db:migrate”时出现错误

-- add_column(:stores, :lat, :decimal, {:precision=>10, :scale=>6})
rake aborted!
StandardError: An error has occurred, all later migrations canceled:

wrong number of arguments (given 4, expected 3)

在 Rails 6 中添加列的正确方法是什么?

参考官方文档总是好的,这里是add_column方法: https://api.rubyonrails.org/v7.0.4/classes/ActiveRecord/ConnectionAdapters/SchemaStatements.html#method-i-add_column

如果出于某种原因你想坚持使用 hash 语法,只要你去掉大括号,你所拥有的语法应该仍然有效。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM