---
title: "Comment by Ishaq Bhallil on \"Implementing ULIDs in Ruby on Rails with PostgreSQL\" | Hashnode"
description: "add this forget about it #config/initializers/ulid_primary_key_defaults.rb module ActiveRecord module ConnectionAdapters class TableDefinition alias_method :ori"
url: "https://hashnode.com/posts/implementing-ulids-in-ruby-on-rails-with-postgresql/65e4e52e881e844aa8696e3c/comment/67af84e3c41bea653aa89588"
---

[Discussion](https://hashnode.com/posts/implementing-ulids-in-ruby-on-rails-with-postgresql/65e4e52e881e844aa8696e3c)

Comment [Implementing ULIDs in Ruby on Rails with PostgreSQL](https://hashnode.com/posts/implementing-ulids-in-ruby-on-rails-with-postgresql/65e4e52e881e844aa8696e3c)

[Ishaq Bhallil](https://hashnode.com/@isbhallil)

[Feb 14, 2025](https://hashnode.com/posts/implementing-ulids-in-ruby-on-rails-with-postgresql/65e4e52e881e844aa8696e3c/comment/67af84e3c41bea653aa89588)

add this forget about it

#config/initializers/ulid\_primary\_key\_defaults.rb module ActiveRecord module ConnectionAdapters class TableDefinition alias\_method :original\_primary\_key, :primary\_key

def primary\_key(name, type = :bigint, **options) if type == :ulid && !options.key?(:default) options\[:default\] = -> { "gen\_ulid()" } end original\_primary\_key(name, type,** options) end end end end

[Ishaq Bhallil](https://hashnode.com/@isbhallil)

[Feb 14, 2025](https://hashnode.com/posts/implementing-ulids-in-ruby-on-rails-with-postgresql/65e4e52e881e844aa8696e3c/comment/67af84e3c41bea653aa89588#reply-67af85239bfa1654b6e21e51)

here is the migration after "

create\_table :users, id: :ulid do |t| t.string :name t.timestamps end

"
