

This mode is also active if no relationMode is explicitly set in the datasource block. You should also enable this option when you use the MySQL connector with a PlanetScale database.įor MongoDB, the only available option is the prisma relation mode.

prisma: this emulates relations in Prisma Client.This is the default option for all relational database connectors and is active if no relationMode is explicitly set in the datasource block. foreignKeys: this handles relations in the database with foreign keys.The relationMode field was renamed in Prisma version 4.5.0, and was previously named referentialIntegrity.įor relational databases, the available options are:

The ability to set the relation mode was introduced as part of the referentialIntegrity preview feature in Prisma version 3.1.1, and is generally available in Prisma versions 4.8.0 and later. To set the relation mode, add the relationMode field in the datasource block: How to set the relation mode in your Prisma schema In cases where the underlying database supports foreign keys, it is usually the preferred choice. There are performance implications to emulation of referential integrity and referential actions in Prisma Client. When you use Prisma Client with the prisma relation mode enabled, the behavior of queries is identical or similar, but referential actions and some constraints are handled by the Prisma engine rather than in the database. For these situations, Prisma offers the prisma relation mode, which emulates some properties of relations in relational databases. Additionally, in some cases developers may prefer not to use foreign keys in their relational database that usually does support foreign keys. Some databases, such as MongoDB or PlanetScale, do not support foreign keys. If you update or delete a user then the ON DELETE and ON UPDATE referential actions specify the CASCADE option, which will also delete or update all posts belonging to the user. In this case, the foreign key constraint on the authorId column of the Post table references the id column of the User table, and guarantees that a post must have an author that exists. REFERENCES "User" ( "id" ) ON DELETE CASCADE ON UPDATE CASCADE
