I’m trying to set delete rules in Studio, but keep running into constraint violations. Specifically, I have a one-to-many relationship between a visit table (one) and problem table (many). Each side has a foreign key to the other.
When a visit is deleted, I want all the problems to also be deleted. How do I set the “on delete” and “on inverse delete” rules for this? I’ve tried many combinations, but keep getting an FK constraint violation on the visit table side.
Hi Eric, >I have a one-to-many relationship between a visit table (one) and problem table (many). Each side has a foreign key to the other.
Probably you have a foreign key (a column) in in Problem table and an inverse attribute (mappedBy, no column) in Visit. So you should annotate Visit.problems attribute with @OnDelete(CASCADE). Also, keep in mind that OnDelete rules take effect only on soft deleted entities. If your entities do not implement SoftDelete, define cascade deletion on database layer in foreign keys.