Another possible solution (but more a workaround) would be to catch errors for SQL STATE `23xxx` and just ignore it. But it's less clean and could result in ignoring false positives because it ignores all constraint violations.