Ruby on Rails

How to use UUID as a primary key in Rails 5.1+ and PostgreSQL

First of all, we need to enable PostgreSQL "pgcrypto" and "uuid-ossp" it’s called extension let’s try to generate a migration for these

now open this file from db/migrate/TIMESTAMPS_enable_pgcrypto_extension.rb and update like below

now complete the migration

now open application.rb and put these codes

Great! You have done the technical steps.

Now need to create a table as like posts then the command looks like this

then open up this file and update like below

complete the migration after the edit.

Completely done the primary key as a UUID.

Fool Dev

I didn't get trained by the school system like other kids, and when I did concentrate on learning, my mind was cluttered and locked by the programming of the system. © Huey Newton