A foreign key links data in one table to data in another table. For example, records in a Posts table might have a foreign key named authorId that refers to the id column of the User table. This relationship makes it possible to, for example, find all blog posts by a particular author.

The Prisma schema represents tables as models, and connections between two models are called relations. You can filter and query by relations - for example, you can get all posts where the author's email address contains "prisma.io".

This section describes how to configure foreign key relationships for different databases. When you introspect a database, these relationships are represented in the Prisma schema as relations.

foreign keys illustration

In this section

Edit this page on GitHub