Adding a reference to an existing table that uses a UUID

Jason Gong
2 min readOct 11, 2021

I added a reference to an existing table for the first time the other day, technically so. Let me explain.

When working by yourself on a toy app you have the option of manually editing existing migrations. When working on a production app with a team, you do not have that luxury. The right to do it is add a new migration that adds or removes what you want to do.

On top of adding a reference to an existing table, I did so to one that uses an UUID for its ID ( Universally unique identifier ). UUIDs are great as an added security measure to any app by the way. You should consider using it in your app if you do not.

Adding it is a simple thing, but doing it for the first time adds complication. What is the command to run and how is it structured. I know it is a migration, but what do I need to add. A quick look at the docs and I get the command

The actual migration came with an error and a bit of learning. First my original migration.

Heres the error:

…and a bit of googling produces an answer

Just needed to set the type in the migration. The answer for this error was much harder to come by than it should have been as google sent me down a rabbit hole in the wrong direction.

Thats all folks. A quick post that I want to share. If you are interested in finding out more about UUIDs, take a look at the link below. There is some bad that comes with its good, but it is mostly worth it to me.

--

--