active_record_bulk_insert icon indicating copy to clipboard operation
active_record_bulk_insert copied to clipboard

Mysql2::Error: Incorrect integer value: 'times' for column 'status' at row 1

Open bindiry opened this issue 7 years ago • 2 comments

My model class has enum(status column default value is 0):

class NodeType < ApplicationRecord
  enum status: { times: 0, monthly: 1 }, _prefix: :status
end
NodeType.bulk_insert([{name: 'a'}, {name: 'b'}])

I had issue like this:

ActiveRecord::StatementInvalid (Mysql2::Error: Incorrect integer value: 'times' for column 'status' at row 1:       INSERT INTO `node_types`
        (name, status, created_at, updated_at)
      VALUES
        ('a', 'times', '2017-04-17 21:19:14.793366', '2017-04-17 21:19:14.793366'),('b', 'times', '2017-04-17 21:19:14.794052', '2017-04-17 21:19:14.794052')
):

How to change status default value to 0?

bindiry avatar Apr 17 '17 13:04 bindiry

have you tried:

NodeType.bulk_insert([{name: 'a', times: 0}, {name: 'b', times: 0}])

bjhaid avatar Apr 18 '17 14:04 bjhaid

@bjhaid

Yes, I tried. I even tried like this:

NodeType.bulk_insert([{name: 'a', times: NodeType.statuses[:times]}, {name: 'b', times: 0}])

It still doesn't work.

bindiry avatar Apr 18 '17 23:04 bindiry