$ cat using-uuids-as-primary-keys-in-rails-apps.md

Using UUIDs as primary keys in Rails apps

September 23, 2025

If you are using UUIDs as primary keys in your Rails application, you may find it tedious to specify them in every single migration. Fortunately, Rails provides a clean way to set this configuration globally so that all new tables use UUIDs automatically.

By adding a simple generator configuration to your config/application.rb, Rails will handle the primary key type for you. Inside your application class, define:

config.generators do |g|
  g.orm :active_record, primary_key_type: :uuid
end

With this setting in place, any time you generate a new model, Rails will create migrations that use UUIDs as the default primary key. This eliminates repetitive setup and ensures consistency across your database schema. It’s a small change that can save you time!

  • Finder
    Finder
  • Jesse Waites
    Jesse Waites
  • Xcode
    Siri
  • Simulator
    Simulator
  • Testflight
    Testflight
  • SF Symbols
    SF Symbols
  • Icon Composer
    Icon Composer
  • Sketch
    Sketch
  • VS Code
    VS Code
  • Postgres
    Postgres
  • Android Studio
    Android Studio
  • Trash
    Trash