Use UUID as primary key on Rails with Postgres
Just enable the uuid-ossp
extension and set the id
field with uuid
:
class CreateUsers < ActiveRecord::Migration[5.0]
def change
enable_extension 'uuid-ossp'
create_table :users, id: :uuid do |t|
t.string :name
t.timestamps
end
end
end
Tweet