-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MDEV-8524: Improve error messaging when there is duplicate key or for…
…eign key names Added better error message that will be printed when foreign key constraint name in create table is not unique in database.
- Loading branch information
Jan Lindström
committed
Jul 31, 2015
1 parent
392df76
commit e05cd97
Showing
8 changed files
with
350 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
CREATE TABLE t1 ( | ||
id int(11) NOT NULL PRIMARY KEY, | ||
a int(11) NOT NULL, | ||
b int(11) NOT NULL, | ||
c int not null, | ||
CONSTRAINT test FOREIGN KEY (b) REFERENCES t1 (id) | ||
) ENGINE=InnoDB DEFAULT CHARSET=latin1; | ||
CREATE TABLE t2 ( | ||
id int(11) NOT NULL PRIMARY KEY, | ||
a int(11) NOT NULL, | ||
b int(11) NOT NULL, | ||
c int not null, | ||
CONSTRAINT test FOREIGN KEY (b) REFERENCES t2 (id) | ||
) ENGINE=InnoDB DEFAULT CHARSET=latin1; | ||
ERROR HY000: Can't create table 'test.t2' (errno: 121) | ||
show warnings; | ||
Level Code Message | ||
Warning 121 InnoDB: foreign key constraint name `test/test` already exists on data dictionary. Foreign key constraint names need to be unique in database. Error in foreign key definition: CONSTRAINT `test` FOREIGN KEY (`b`) REFERENCES `test`.`t2` (`id`). | ||
Error 1005 Can't create table 'test.t2' (errno: 121) | ||
drop table t1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
--source include/have_innodb.inc | ||
|
||
# | ||
# MDEV-8524: Improve error messaging when there is duplicate key or foreign key names | ||
# | ||
CREATE TABLE t1 ( | ||
id int(11) NOT NULL PRIMARY KEY, | ||
a int(11) NOT NULL, | ||
b int(11) NOT NULL, | ||
c int not null, | ||
CONSTRAINT test FOREIGN KEY (b) REFERENCES t1 (id) | ||
) ENGINE=InnoDB DEFAULT CHARSET=latin1; | ||
|
||
# | ||
# Below create table fails because constraint name test | ||
# is reserved for above table. | ||
# | ||
--error 1005 | ||
CREATE TABLE t2 ( | ||
id int(11) NOT NULL PRIMARY KEY, | ||
a int(11) NOT NULL, | ||
b int(11) NOT NULL, | ||
c int not null, | ||
CONSTRAINT test FOREIGN KEY (b) REFERENCES t2 (id) | ||
) ENGINE=InnoDB DEFAULT CHARSET=latin1; | ||
|
||
show warnings; | ||
|
||
drop table t1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.