Sometimes, we want to set a primary key of a database table to be a string instead of integer. This is perfectly OK though not best.

However, seems this is not possible when creating tables by using ruby on rails. This post helps a lot.

The following is the sample code:

create_table :employees, {:id => false} do |t|
t.string :emp_id
t.string :first_name
t.string :last_name
end
execute "ALTER TABLE employees ADD PRIMARY KEY (emp_id);"



More...