Create Foreign Key
todos table, the value of
user_id column must be ideally present in the
id column of
users table. Otherwise, it would result in inconsistent data.
Postgres allows you to define foreign key constraint to enforce this condition.
Let's define one for the
user_id column in
Head over to Console -> DATA -> todos -> Modify page.
It should look something like this:
Scroll down to
Foreign Keys section at the bottom and click on
- Select the Reference table as
- Choose the From column as
user_idand To column as
We are enforcing that the
user_id column of
todos table must be one of the values of
Save to create the foreign key.
Great! Now you have ensured data consistency.
Did you find this page helpful?
Start with GraphQL on Hasura for Free
- Build apps and APIs 10x faster
- Built-in authorization and caching
- 8x more performant than hand-rolled APIs