Check out this answer . Try execute "ALTER TABLE shareholders ADD PRIMARY KEY (uid);" without specifying the primary_key parameter in the create_table block.
I suggest writing your migration as follows (so you can roll back normally):
class CreateShareholders < ActiveRecord::Migration def up create_table :shareholders, id: false do |t| t.integer :uid, limit: 8 t.string :name t.integer :shares t.timestamps end execute "ALTER TABLE shareholders ADD PRIMARY KEY (uid);" end def down drop_table :shareholders end end
UPD: There is a natural way ( found here ), but only with type int4:
class CreateShareholders < ActiveRecord::Migration def change create_table :shareholders, id: false do |t| t.primary_key :uid t.string :name t.integer :shares t.timestamps end end end
source share