[英]n Rails 6, what's the proper way to add a decimal column to a table via a migration?
I just upgraded to Rails 6.1.4.4 and a migration that previously passed in Rails 4 fails in the new set up.我刚刚升级到 Rails 6.1.4.4,之前在 Rails 4 中通过的迁移在新设置中失败了。 It is
这是
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
Now I get the error when I run “rake db:migrate”现在当我运行“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)
What's the proper way to add a column in Rails 6?在 Rails 6 中添加列的正确方法是什么?
Always good to reference the official docs, here's for the add_column
method: https://api.rubyonrails.org/v7.0.4/classes/ActiveRecord/ConnectionAdapters/SchemaStatements.html#method-i-add_column参考官方文档总是好的,这里是
add_column
方法: https://api.rubyonrails.org/v7.0.4/classes/ActiveRecord/ConnectionAdapters/SchemaStatements.html#method-i-add_column
If you want to stick to the hash syntax for some reason what you had should still work as long as you drop the curly braces.如果出于某种原因你想坚持使用 hash 语法,只要你去掉大括号,你所拥有的语法应该仍然有效。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.