Bug #46337 | Inconsistent MySQL behavior when creating a table with self-ref. FKs | ||
---|---|---|---|
Submitted: | 22 Jul 2009 10:39 | Modified: | 12 Apr 2019 18:27 |
Reporter: | Vladimir Kolesnikov | Email Updates: | |
Status: | Closed | Impact on me: | |
Category: | MySQL Server: General | Severity: | S3 (Non-critical) |
Version: | 5.1.35 | OS: | Any |
Assigned to: | CPU Architecture: | Any |
[22 Jul 2009 10:39]
Vladimir Kolesnikov
[22 Jul 2009 21:39]
Sveta Smirnova
Thank you for the report. Verified as described.
[12 Apr 2019 13:37]
Dmitry Lenev
Posted by developer: Hello! After bug #27506922 "DROPPING OF PARENT KEY FOR FOREIGN KEY IS ALLOWED" has been fixed in MySQL Server 8.0.12, SQL-layer checks that there is existing parent key for the foreign key and reports an error if it is missing. For example: create table t1 (c1 int, c2 int, constraint fk1 foreign key (c1) references t1 (c2)) # Fails with ERROR 1822 (HY000): Failed to add the foreign key constraint. Missing index for constraint 'fk1' in the referenced table 't1' So Oracle's and 3rd party storage engines can rely on this check present. Thus I am closing this bug as fixed in 8.0.12. Moving this bug to Documenting state to let Documentation team to decide if anything needs to be added to release notes.
[12 Apr 2019 18:27]
Paul DuBois
Posted by developer: Fixed in 8.0.12. It was possible to drop a primary key that served as the parent key in a foreign key relationship. In addition, for table creation, the SQL layer now checks whether there is a parent key for the foreign key and reports an error if it is missing.