Bug #87283 Wrong warning message during foreign key creation failure (not compatible chars

Submitted: 2 Aug 2017 12:09 Modified: 10 Aug 2017 10:18
Reporter: Sveta Smirnova (OCA) Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: Errors Severity:S4 (Feature request)
Version:5.5, 5.6, 5.7, 8.0, 5.7.19 OS:Any
Assigned to: CPU Architecture:Any

[2 Aug 2017 12:09] Sveta Smirnova
Description:
Originally reported at https://bugs.launchpad.net/percona-server/+bug/1705229

MySQL server reports misleading warning when foreign key creation fails due to incompatible foreign key character set.

How to repeat:
test> create table a(id varchar(1) character set utf8mb4, primary key(id));
test> create table b(id varchar(1) character set utf8, b_id varchar(1) character set utf8, primary key(id), CONSTRAINT a_fkey FOREIGN KEY (b_id) REFERENCES a (id));
ERROR 1215 (HY000): Cannot add foreign key constraint
test> show warnings
```
root@perconatraindb03-sjc1 test> show warnings;
+---------+------+----------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Level | Code | Message |
+---------+------+----------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Warning | 150 | Create table 'test/b' with foreign key constraint failed. There is no index in the referenced table where the referenced columns appear as the first columns.
 |
| Error | 1215 | Cannot add foreign key constraint |
+---------+------+----------------------------------------------------------------------------------------------------------------------------------------------------------------+
2 rows in set (0.00 sec)
```

Suggested fix:
Something more meaningful than column not appearing in index a first column.
[2 Aug 2017 12:09] Sveta Smirnova
test case for MTR

Attachment: bug1705229.test (application/octet-stream, text), 311 bytes.

[10 Aug 2017 10:18] MySQL Verification Team
Hello Sveta,

Thank you for the reasonable feature request!

Thanks,
Umesh

Portions of this website are copyright © 2001, 2002 The PHP Group

Page generated in 0.060 sec. using MySQL 8.4.7-u6-cloud

Timestamp references displayed by the system are UTC.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.