【问题标题】:rails 4 undefined method `sql_type' in migration迁移中的rails 4未定义方法“sql_type”
【发布时间】:2013-09-03 08:56:59
【问题描述】:

我有以下迁移:

class CreateTariffs < ActiveRecord::Migration
  def change
    create_table :tariffs do |t|
      t.string :name
      t.decimal :amount, precision: 10, scale: 6, default: 0.0
      t.timestamps
    end
  end
end

我的迁移失败,出现以下异常:

undefined method `sql_type' for #<ActiveRecord::ConnectionAdapters::PostgreSQLAdapter::ColumnDefinition:0x000000089a4108>/home/polygalin/.rvm/gems/ruby-2.0.0-p195/gems/activerecord-postgres-array-0.0.9/lib/activerecord-postgres-array/activerecord.rb:42:in `quote_with_array'

但如果我删除“金额”列的默认值,迁移成功。 任何人都可以帮助找出为什么迁移失败并使用小数列的默认值?

【问题讨论】:

标签: ruby-on-rails ruby-on-rails-4 rails-migrations rails-postgresql


【解决方案1】:

我找到了原因。它在 activerecord-postgres-array gem 中。 Active Record 4 已经支持 postgres 数组,我只需将其删除即可迁移成功。

【讨论】:

    【解决方案2】:

    请尝试通过以下更改运行迁移,如果失败,请告诉我。

    class CreateTariffs < ActiveRecord::Migration
      def change
        create_table :tariffs do |t|
          t.string :name
          t.decimal :amount, precision: 10, scale: 6, default: 0.00 # or default: 0
          t.timestamps
        end
      end
    end
    

    【讨论】:

      猜你喜欢
      • 2023-03-08
      • 2017-01-11
      • 1970-01-01
      • 1970-01-01
      • 2019-06-17
      • 2015-09-09
      • 2013-02-04
      • 1970-01-01
      • 2015-02-18
      相关资源
      最近更新 更多