This guide is a sort of extract of official rails guide: Official rails guide
Here I describe an implementation of uuid with PostgreSQL >= 9.4. This requires to enable pgcrypto
Example with a creation of a table named trackers:
class CreateTrackers < ActiveRecord::Migration[5.0]
def change
enable_extension 'pgcrypto' unless extension_enabled?('pgcrypto')
create_table :trackers, id: :uuid, default: 'gen_random_uuid()' do |t|
t.integer :duration, null: false
t.string :description, null: false
t.timestamps
end
end
endYou can use uuid to degine a relation reference