1

次の移行があります。

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'

しかし、「金額」列のデフォルト値を削除すると、移行は成功します。小数点列のデフォルト値で移行が失敗する理由を誰でも見つけることができますか?

4

2 に答える 2

1

理由がわかりました。それはactiverecord-postgres-array gemにありました。Active Record 4 には既に postgres 配列のサポートがあり、それを削除するだけで移行は成功します。

于 2013-09-03T10:12:45.580 に答える
0

次の変更を加えて移行を実行してみて、失敗した場合はお知らせください。

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
于 2013-09-03T10:04:40.093 に答える