简体   繁体   English

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

[英]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.

相关问题 ruby on rails在表中添加列的最佳方法是什么 - ruby on rails what's the best way to add a column to a table 在Rails中执行此操作的正确方法是什么? - What's the proper way to do this in Rails? Gmaps4rails:通过AJAX添加标记后启用集群的正确方法是什么? - Gmaps4rails: What's the proper way to enable clustering after adding markers via AJAX? 通过rails中的迁移添加自动增量 - Add autoincrement via migration in rails 在rails应用程序,夹具或迁移中添加样本数据的最佳方法是什么? - What is the best way of add sample data in rails application, fixtures or migration? 显示通过Nokogiri抓取的数据的正确方法是什么? - What's the proper way to display data scraped via Nokogiri? 使用React设计Ruby on Rails应用程序的正确方法是什么 - What's a proper way to design Ruby on Rails application with React 从github克隆后安装rails的正确方法是什么? - What's the proper way to install rails after cloning from github? 查看Rails应用程序的网站统计信息的正确方法是什么? - What is the proper way to see rails application's web site statistics? 在Rails中初始化class_attribute的正确方法是什么? - What's the proper way to initialize a class_attribute in Rails?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM