← All postsDeveloper writing a seed migration with five identifiers pasted into a SQL editor

Generate Five UUIDs for a Database Seed Migration

Create random version 4 UUIDs for roles, tenants or test rows in a seed script, with a sample SQL insert and checks before you commit.

UUID generatorseed datadatabase migrationprimary keysUUID v4SQL inserttest fixturesbrowser tools
4 min readDeveloper & Security Tools

Your migration needs to insert five default roles, and the foreign keys elsewhere in the same file must point at the exact same identifiers. If you let the database generate them at insert time, the later statements cannot reference them. Pre-generating the values and pinning them in the script is the fix, and UUID Generator hands you a batch in one click.

Press Generate and the page produces random UUIDs using the browser's own cryptographic generator. Nothing is sent to a server to create them, and the list exists only on the page until you leave it.

How to Generate UUID Online Random Unique Keys

How to Generate UUID Online Random Unique Keys

A worked seed: five roles, five fixed ids

Leave Count at 5 and press Generate. One run produced values like these:

  • 4bfdd325-53ec-4ca1-a22e-e9468ed11dc9
  • 7b673879-20c2-4784-a3ff-6f454672dc27
  • 69273e3d-7b7c-4faf-b302-174119364e06
  • 5dff6ea4-635a-4b52-a3e4-5c53a33444e8
  • 5f08172c-ec6f-428a-a17a-664a66d29243

Yours will differ, which is the point. Paste them into the seed so each role keeps its id forever: INSERT INTO roles (id, name) VALUES ('4bfdd325-…', 'owner'), ('7b673879-…', 'admin'), ('69273e3d-…', 'editor'), ('5dff6ea4-…', 'viewer'), ('5f08172c-…', 'billing');. A later statement that grants permissions can then reference the owner id literally, and every environment (local, staging, production) ends up with identical role ids.

Commit those values to version control as they are. Regenerating them on a later run would break every row that already references the old ones.

Steps in the tool

  1. Type how many you need in Count. The page accepts 1 to 1,000 per press. A larger number is capped at 1,000 with a note, and zero, a negative number or text shows a message asking for a whole number from 1 up.
  2. Press Generate. Each press of the button counts as one of your 10 trial usages for the day, so decide the count first rather than clicking repeatedly.
  3. Copy a single value with the copy icon beside it, or press Copy All to get the whole list, one per line.
  4. Paste straight into your script, fixture file or spreadsheet.
  5. Copy what you need before generating again or reloading, because a new press replaces the list and nothing is stored.

What these values are, and are not

The tool creates version 4 UUIDs, which are built from random bits. A UUID is 36 characters long: 32 hexadecimal digits in groups of 8, 4, 4, 4 and 12. In a version 4 value the first digit of the third group is always 4, and the first digit of the fourth group is one of 8, 9, a or b. Check the sample list: the third groups are 4ca1, 4784, 4faf, 4b52 and 428a, all starting with 4, and the fourth groups start with a, a, b, a and a.

It does not offer version 1, name-based version 5 or the newer time-ordered versions, and it adds no braces. Hyphens can be switched off and Uppercase switched on. If a system wants braces, paste the list into Find and Replace or change case in your code.

How unlikely is a collision?

A version 4 UUID carries 122 random bits. Even if you generated a billion identifiers, the chance of any pair matching is roughly 1 in 10 quintillion, far below the risk of a disk error. For normal projects you can treat them as unique across separate machines without coordination.

Keep a unique constraint on the column anyway. The constraint is cheap, it catches a copy-paste mistake such as the same id pasted twice, and it protects you from values that were not generated by this tool at all.

Validate before you commit

Before running the migration, check the pasted ids with a quick pattern in the Regex Tester. A pattern such as ^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$ should match every line of your list. A line that fails usually has a stray space, a missing character or a character dropped when copying from a chat window.

Also scan for duplicates between your seed file and any test fixtures. Sorting the list and looking for neighbours that match takes seconds, and finding a repeat by hand is far cheaper than debugging a failed constraint on a deployment night.

When a UUID is the wrong choice

Random UUIDs are not secrets. They are good identifiers, but they are not API keys, passwords or session tokens, and they should not be the only thing standing between a stranger and private data. For credentials, use a generator built for secrets.

They are also unordered. If your database indexes the primary key and you insert millions of rows, purely random keys scatter writes across the index, which some teams avoid with time-ordered identifiers. That is a design decision for your stack, and this tool does not generate those. Neighbouring developer utilities sit in the security tools category, part of the 300+ professional tools, premium applications and workflow products on the site.

Common mistakes

  • Generating fresh ids on each deploy so references drift between environments.
  • Pasting a list with trailing spaces or Windows line endings into a SQL string.
  • Pressing Generate again after copying part of the list and losing the rest.
  • Treating a UUID as unguessable and using it as the access control for a download link.
  • Assuming Count above 1,000 will give you more. The page caps each press at 1,000, so press twice and merge the lists.

Closing next step

Decide how many ids your seed needs, generate them once, commit them with the migration, and run the pattern check. Then try the batch in a throwaway database before production. Open UUID Generator when you are ready.

Would you like to see other UUID versions, uppercase output or a one-click SQL insert template? Tell us on the contact page.

Open UUID GeneratorOpen Regex TesterOpen Find & Replace