This is a perfect candidate for a foreign key constraint! Let's get real crazy and pretend that we also have an addresses table with a user_id column referring to-stay with me-the users table. Let's imagine that we have a very innovative app with a users table. If you underestimate the impact that adding them can have on your running application, you will be severely burned.įortunately, there are a few sweet morsels of knowledge that will spare you this pain. Adding foreign key constraints, like many schema changes in Postgres (and pretty much all database engines for that matter), should never be taken lightly.
When I think about foreign keys in Postgres, I shudder with fear recalling the pain and suffering they've caused me.