BIGINTs in rails as primary keys

(This is an update to my older post on bigints in rails migrations.)

BIGINT columns in rails have always been a little annoying to work with, which is why I published a blog post on how to do it, five years ago, to serve as a reminder to myself and as a resource to others. BIGINT primary keys were even more hit-and-miss.

Enter Ryuta “kamipo” Kamizono, who took to improving rails’ support for this, created a pull request “Allow limit option for MySQL bigint primary key support,” and landed that in rails:master last month, which allows you to write things like this:


create_table :foos, id: :primary_key, limit: 8 do |t|
end

# or

create_table :foos, id: false do |t|
  t.primary_key :id, limit: 8
end

The patch should be included in the next release of rails. Happy hacking!