rails3 bigint primary key

I had the same problem. I think the easiest way for a table

accounts 
id bigint primary key 
name char 

is

create_table :accounts do |t|
t.string :name
end
change_column :accounts, :id , "bigint NOT NULL AUTO_INCREMENT"

Had that myself not long ago and found the answer here: Using Rails, how can I set my primary key to not be an integer-typed column?

You need to set primary_key: false and then use a custom statement before you execute the migration.

EDIT 1: You need to check your database docs for the exact query to perform. It is executed as a regular SQL statement and needs to be database specific. The example in the question I referred to is for Postgre SQL. If you are on MySQL you might have to change that.


For MySQL you can use "SERIAL" which is alias for "BIGINT UNSIGNED NOT NULL AUTO_INCREMENT"

class ChangeUserIdToBigint < ActiveRecord::Migration
  def change
    change_column :users, :id, 'SERIAL'
  end
end