migration to enable uuid in postgres class EnableUuidExtension < ActiveRecord::Migration[5.0] def change enable_extension 'uuid-ossp' end end migration to make the model use uuid as its primary id class CreateArticles < ActiveRecord::Migration[5.0] def change create_table :articles, id: :uuid do |t| t.timestamps end end end migration to make the relation model use uuid as its id class CreateComments < ActiveRecord::Migration[5.0] def change create_table :comments do |t| t.timestamps t.uuid :article_id end add_index :comments, :article_id end end