Is it possible to detect exactly which database constraint was violated during exception handling? #5467

Closed
opened 2026-01-22 15:08:27 +01:00 by admin · 1 comment
Owner

Originally created by @BabakMN on GitHub (Mar 17, 2017).

Originally assigned to: @Ocramius on GitHub.

I'd like to know if it's possible to detect which constraint was violated during a constraint violation exception?

Or alternatively, which column(s) was involved.

The use case is for when multiple unique constraints are placed on a table and then an insert fails because of a violation.

For complete error handling you would need to know exactly which constraint was involved in the violation.

This can be done by doing a string search on the text of the error message however I'm wondering if a better solution is available.

Originally created by @BabakMN on GitHub (Mar 17, 2017). Originally assigned to: @Ocramius on GitHub. I'd like to know if it's possible to detect which constraint was violated during a constraint violation exception? Or alternatively, which column(s) was involved. The use case is for when multiple unique constraints are placed on a table and then an insert fails because of a violation. For complete error handling you would need to know exactly which constraint was involved in the violation. This can be done by doing a string search on the text of the error message however I'm wondering if a better solution is available.
admin added the ImprovementWon't FixQuestion labels 2026-01-22 15:08:27 +01:00
admin closed this issue 2026-01-22 15:08:27 +01:00
Author
Owner

@Ocramius commented on GitHub (Mar 17, 2017):

The error message already provides this information: this is not something
that the ORM should do, but rather your rdbms.

On 17 Mar 2017 1:50 a.m., "BabakMN" notifications@github.com wrote:

I'd like to know if it's possible to detect which constraint was violated
during a constraint violation exception?

Or alternatively, which column(s) was involved.

The use case is for when multiple unique constraints are placed on a table
and then an insert fails because of a violation.

For complete error handling you would need to know exactly which
constraint was involved in the violation.

This can be done by doing a string search on the text of the error message
however I'm wondering if a better solution is available.


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/doctrine/doctrine2/issues/6347, or mute the thread
https://github.com/notifications/unsubscribe-auth/AAJakO4z9q6r28xhqavJFXbkO7V9ACMdks5rmdjGgaJpZM4MgDf-
.

@Ocramius commented on GitHub (Mar 17, 2017): The error message already provides this information: this is not something that the ORM should do, but rather your rdbms. On 17 Mar 2017 1:50 a.m., "BabakMN" <notifications@github.com> wrote: > I'd like to know if it's possible to detect which constraint was violated > during a constraint violation exception? > > Or alternatively, which column(s) was involved. > > The use case is for when multiple unique constraints are placed on a table > and then an insert fails because of a violation. > > For complete error handling you would need to know exactly which > constraint was involved in the violation. > > This can be done by doing a string search on the text of the error message > however I'm wondering if a better solution is available. > > — > You are receiving this because you are subscribed to this thread. > Reply to this email directly, view it on GitHub > <https://github.com/doctrine/doctrine2/issues/6347>, or mute the thread > <https://github.com/notifications/unsubscribe-auth/AAJakO4z9q6r28xhqavJFXbkO7V9ACMdks5rmdjGgaJpZM4MgDf-> > . >
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#5467