Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #5219 (assigned task)

Opened 4 years ago

Last modified 2 years ago

ActiveRecord::Migration cannot create unsigned int for Mysql

Reported by: max@maxidoors.ru Assigned to: jon@blankpad.net (accepted)
Priority: normal Milestone: 2.x
Component: ActiveRecord Version: edge
Severity: normal Keywords: migration int unsigned
Cc: jon@blankpad.net

Description

I have to keep IP adresses as integers in database. I'm creating :integer, :limit => 11 and Migrator creates mysql int(11). But this doesn't help and I have to create int(11) unsigned by hands.

It would be good to add a patch, that allows to create unsigned integer in database. I can create this patch, if maintainer is busy.

Change History

08/29/06 06:10:23 changed by bitsweat

  • status changed from new to closed.
  • type changed from task to enhancement.
  • resolution set to wontfix.
  • milestone changed from 1.2 to 1.x.

Unsigned integers are an uncommon requirement. Please reopen with a patch and tests if you pursue this.

08/30/06 07:23:32 changed by zdennis@mktec.com

  • type changed from enhancement to task.
  • milestone changed from 1.x to 1.2.
Unsigned integers are an uncommon requirement. Please reopen with a 
patch and tests if you pursue this.

I dont 'know if this is uncommon, but it was recently brought to my attention you can do this by using 'integer unsigned' rather then :integer. That may or may not solve your original issue.

ie:

 t.column :position, 'integer unsigned'

02/15/08 16:11:15 changed by jon@blankpad.net

  • cc set to jon@blankpad.net.

02/15/08 16:17:51 changed by jon@blankpad.net

  • status changed from closed to reopened.
  • version changed from 1.1.1 to edge.
  • resolution deleted.
  • milestone changed from 1.2 to 2.x.

The documentation for ActiveRecord suggests using an unsigned int for you ID field (line 181), which makes complete sense - ids shouldn't be negative, so why not let the database enforce that.

I'm reopening this, and will write patch to allow :unsigned => true in the options for an integer field, and to default IDs to using them unless anyone has a good reason not to.

02/15/08 16:18:23 changed by jon@blankpad.net

  • owner changed from thomas@fesch.at to jon@blankpad.net.
  • status changed from reopened to new.

02/15/08 16:18:52 changed by jon@blankpad.net

  • status changed from new to assigned.