paper_trail: item_id out of range for mysql

have a User model with a simple has_paper_trail and all default options. no other modifiers. fresh database off of a db reset plus the run of a seeds file with some dummy data yielded:

rake aborted! Mysql2::Error: Out of range value for column ‘item_id’ at row 1: INSERT INTO versions (created_at, event, item_id, item_type, object, whodunnit) VALUES (‘2013-07-24 08:11:19’, ‘create’, 9554302037, ‘User’, NULL, NULL)

looks like the auto-generated item_id is doing an overrun of the mysql int? the weird thing is i haven’t changed this seeds file in a long time (weeks?) and have run it literally hundreds if not thousands of times with no errors and so this is not reproduce-able. it worked on a reset and re-run. nonetheless might be good to look at how those are generated?

also, just fyi, the table was generated with the default migration from the generator…

class CreateVersions < ActiveRecord::Migration def self.up create_table :versions do |t| t.string :item_type, :null => false t.integer :item_id, :null => false t.string :event, :null => false t.string :whodunnit t.text :object t.datetime :created_at end add_index :versions, [:item_type, :item_id] end

def self.down remove_index :versions, [:item_type, :item_id] drop_table :versions end end

not sure what’s up. it’s also late and i could be doing something stupid, but don’t think so. let me know. thanks.

About this issue

  • Original URL
  • State: closed
  • Created 11 years ago
  • Comments: 17

Most upvoted comments

Yes, we are using ActiveUUID (https://github.com/jashmenn/activeuuid) and the table is set to use this as the primary key:

create_table :example, :id => false do |t|
  t.uuid :id, :primary_key => true
  ...
end
+------------------+--------------+------+-----+---------+-------+
| Field            | Type         | Null | Key | Default | Extra |
+------------------+--------------+------+-----+---------+-------+
| id               | binary(16)   | NO   | PRI | NULL    |       |

I was able to get around this problem though by setting the column to ‘uuid’ instead (per ActiveUUID convention):

create_table :versions do |t|
  t.uuid     :item_id,   :null => false
  ...
end

But I’m not sure whether this is a good long term fix because it disallows us to use paper trail for our tables which don’t have a UUID as their primary key.

@craigsheen Is correct that the ‘string’ fix didn’t work here because mysql is refusing the UTF8 encoding, so we may look at reconfiguring the db instead.

Any thoughts welcome!