DataMapper out of range value for column ‘id’

If you are reading this, you are (probably) using DataMapper and are having problems like this:

Exception `DataObjects::DataError' at dm-do-adapter/adapter.rb:279
Out of range value for column 'id' at row 1 (code: 1264, sql state: 22003, 
query: INSERT INTO `workspaces` (`id`, `name`) VALUES (2348944937325, 'Stardata S.r.l.')
[...]

The problem is that the default field created by DataMapper for an Integer property is a 32bit INT (at least on MySQL 5.5). If you want to store bigger integers you should use the :min and :max parameters, for example:

class Workspace
  include DataMapper::Resource

  property :id, Integer, :key => true, :min => 0, :max => 281474976710656
  property :name, String

end

Then DataMapper will use a BIGINT for the field.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s