Bug #25826 Unique keys: show constraint name in error message
Submitted: 24 Jan 2007 13:26 Modified: 16 Feb 2007 12:58
Reporter: Sanjay Patil Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: Errors Severity:S4 (Feature request)
Version:5.0.36-BK, mysql-5.2.0-falcon-alpha-win32 OS:Windows (Windows 2000/XP)
Assigned to: CPU Architecture:Any

[24 Jan 2007 13:26] Sanjay Patil
Description:
Hi,

I am testing current latest version "mysql-5.2.0-falcon-alpha-win32"
regarding our issue of constraint name not displayed on violation.

When the foreign key is violeted, I see constraint name displayed in
the error message like shown below.

####################
[root@localhost:3306] ERROR 1452: Cannot add or update a child row: a
foreign key constraint fails (`mydb`.`child`, CONSTRAINT `fk_child`
FOREIGN KEY (`id`) REFERENCES `parent` (`id`))
####################

But still if the primary key is violeted I get message

####################
[root@localhost:3306] ERROR 1062: Duplicate entry '3' for key
'PRIMARY'
####################

Will it be possible to display more readable message like

###########
Can not insert duplicate value. Primary constraint 'pk_parent' of table 'parent' is violated for entry '3'"
###########

instead of text "for key 'PRIMARY'"

Thanks

Sameer

How to repeat:
1) Creat table and define primary key
2) Insert few unique records
3) Insert again previously inserted record which will violate primary constarint.

The resulting message does not display constraint name and table name.

Suggested fix:
Display table name and constraint name on constraint violation.
[16 Feb 2007 12:58] Valeriy Kravchuk
Thank you for a reasonable feature request. 

We really need to be able to store a name for a primary key contraint and output information about PK violation in a way similar to foreign key violation (at least, with table name for a table with PK violated!)