1/16/2024 0 Comments On delete cascade postgres![]() PostgreSQL is the only database supported by Prisma that allows you to define a SetNull referential action that refers to a non-nullable field. In MySQL versions 5.6 and later, and MariaDB versions before 10.5, attempting to create a table definition with the SET DEFAULT referential action fails with a syntax error.įor this reason, when you set mysql as the database provider, Prisma warns users to replace SetDefault referential actions in the Prisma schema with another action.You can define tables using the SET DEFAULT referential action, but a foreign key constraint error is triggered at runtime. In MySQL versions 8 and later, and MariaDB versions 10.5 and later, SetDefault effectively acts as an alias for NoAction.The exact behavior depends on the database version: MySQL, and the underlying InnoDB storage engine, does not support SetDefault. However, there are special cases where some relational databases diverge from the standard. Referential actions are part of the ANSI SQL standard. †† Referential actions for MongoDB are available in Prisma versions 3.7.0 and later.The following model defines a one-to-many relation between User and Post and a many-to-many relation between Post and Tag, with explicitly defined referential actions: If you do not specify a referential action, Prisma falls back to a default. Referential actions are defined in the attribute and map to the actions on the foreign key constraint in the underlying database. In your Prisma schema, this is generally represented by the id field on the related model.īy default a database will reject any operation that violates the referential integrity, for example, by deleting referenced records. Referential integrity states that these foreign keys must reference an existing primary key value in the related database table. These foreign keys connect the models on the database level. When you define relationships between data models in your Prisma schema, you use relation fields, which do not exist on the database, and scalar fields, which do exist on the database. Version locking: Version will not be verified on deletion of cascaded object.Įvents: Deletion events may not be executed on the cascaded objects if the objects are not loaded.Ĭascading: The remove operation should still be configured to cascade in the mapping if using CascadeOnDelete.Įxample 2-18 shows the cascading deletion of the Employee secondary table and all of its owned relationships.Referential actions are features of foreign key constraints that exist to preserve referential integrity in your database. ManyToMany: SQL will not be executed to delete from the join table.ĮlementCollection: SQL will not be executed to delete from the collection table.Ĭache: Cascaded objects will still be removed from the cache and persistence context. OneToMany: If the mapping uses cascading or orphanRemoval, SQL will not be executed to delete target objects. OneToOne: If the mapping uses cascading or orphanRemoval, SQL will not be executed to delete target object. ![]() ![]() The deletion of the collection table is cascaded on the has the following behavior:ĭDL generation: If DDL generation is used, the generated constraint will include the cascade deletion option.Įntity: Remove will not execute SQL for deletion from secondary or joined inheritance tables (as constraint will handle deletion). The deletion of the join table is cascaded on the database (target objects cannot be cascaded even if private because of constraint direction). ![]() This is only allowed for mappedBy/target-foreign key OneToOne mappings (because of constraint direction).įor a OneToMany using a mappedBy or JoinColumn, the deletion of the related objects is cascaded on the database.įor a OneToMany using a JoinTable, the deletion of the join table is cascaded on the database (target objects cannot be cascaded even if private because of constraint direction). The deletion of the related object is cascaded on the database. Table 2-8 Using on Different Elements ElementĮffect of that secondary or joined inheritance tables should cascade the delete on the database ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |