【问题标题】:Rails 3 - dumping PostgreSQL database into schema.rb has incorrect precision for numeric typesRails 3 - 将 PostgreSQL 数据库转储到 schema.rb 对数字类型的精度不正确
【发布时间】:2011-11-29 20:29:08
【问题描述】:

我有一个现有的 postgresql 数据库,我想在新的 rails 应用程序中使用它,所以我首先想使用 rake db:schema:dump 将现有架构转储到 schema.rb 中。但是,当我这样做时,schema.rb 对数字列有一个奇怪的精度值。

create_table "order", :id => false, :force => true do |t|
    ....
    t.decimal  "Quantity",               :precision => 131089, :scale => 0
    ....

在我的 PostgreSQL 数据库中,数字类型列没有明确的精度或比例集。

精度显示出如此巨大的价值是有原因的吗?

我也尝试更改和删除 schema.rb 中的精度修饰符,但每次我进行迁移时,它都会使用这些巨大的值重新生成 schema.rb 文件。我查看了ActiveRecord table definition,但这不是很有帮助。

【问题讨论】:

  • \d orderpsql 内部说了什么?
  • @mu-is-too-short:数量的类型显示为“数字”
  • 表中还有其他内容吗? ActiveRecord::Base.connection.columns('order') 必须从 Rails 控制台说什么?

标签: ruby-on-rails rails-postgresql


【解决方案1】:

我怀疑这被选为 PostgreSQL 中数值的最大精度。见http://www.postgresql.org/docs/9.2/static/datatype-numeric.html

【讨论】:

    猜你喜欢
    • 2016-10-05
    • 1970-01-01
    • 2011-06-21
    • 1970-01-01
    • 2023-03-05
    • 1970-01-01
    • 1970-01-01
    • 2020-01-01
    • 2018-08-16
    相关资源
    最近更新 更多