| 1 |
CREATE TABLE t1 ( |
| 2 |
id int(11) NOT NULL PRIMARY KEY, |
| 3 |
a int(11) NOT NULL, |
| 4 |
b int(11) NOT NULL, |
| 5 |
c int not null, |
| 6 |
CONSTRAINT test FOREIGN KEY (b) REFERENCES t1 (id) |
| 7 |
) ENGINE=InnoDB DEFAULT CHARSET=latin1; |
| 8 |
CREATE TABLE t2 ( |
| 9 |
id int(11) NOT NULL PRIMARY KEY, |
| 10 |
a int(11) NOT NULL, |
| 11 |
b int(11) NOT NULL, |
| 12 |
c int not null, |
| 13 |
CONSTRAINT mytest FOREIGN KEY (c) REFERENCES t1(id), |
| 14 |
CONSTRAINT test FOREIGN KEY (b) REFERENCES t2 (id) |
| 15 |
) ENGINE=InnoDB DEFAULT CHARSET=latin1; |
| 16 |
ERROR HY000: Can't create table `test`.`t2` (errno: 121 "Duplicate key on write or update") |
| 17 |
show warnings; |
| 18 |
Level Code Message |
| 19 |
Warning 121 CREATE or ALTER TABLE `test`.`t2` failed: duplicate name, CONSTRAINT `test` FOREIGN KEY (`b`) REFERENCES `t2` (`id`) |
| 20 |
Error 1005 Can't create table `test`.`t2` (errno: 121 "Duplicate key on write or update") |
| 21 |
Warning 1022 Can't write; duplicate key in table 't2' |
| 22 |
drop table t1; |
| 23 |
create table t1(a int) engine=innodb; |
| 24 |
create table t2(a int, constraint a foreign key a (a) references t1(a)) engine=innodb; |
| 25 |
ERROR HY000: Can't create table `test`.`t2` (errno: 150 "Foreign key constraint is incorrectly formed") |
| 26 |
show warnings; |
| 27 |
Level Code Message |
| 28 |
Warning 150 Create table `test`.`t2` with foreign key `a` constraint failed. There is no index in the referenced table where the referenced columns appear as the first columns. |
| 29 |
Error 1005 Can't create table `test`.`t2` (errno: 150 "Foreign key constraint is incorrectly formed") |
| 30 |
Warning 1215 Cannot add foreign key constraint for `t2` |
| 31 |
drop table t1; |
| 32 |
create table t1(a int unique, b int) engine=innodb; |
| 33 |
create table t2(a int, b int, foreign key (a) references t1(a), foreign key (b) references t1(b)) engine=innodb; |
| 34 |
ERROR HY000: Can't create table `test`.`t2` (errno: 150 "Foreign key constraint is incorrectly formed") |
| 35 |
show warnings; |
| 36 |
Level Code Message |
| 37 |
Warning 150 Create table `test`.`t2` with foreign key (b) constraint failed. There is no index in the referenced table where the referenced columns appear as the first columns. |
| 38 |
Error 1005 Can't create table `test`.`t2` (errno: 150 "Foreign key constraint is incorrectly formed") |
| 39 |
Warning 1215 Cannot add foreign key constraint for `t2` |
| 40 |
drop table t1; |
| 41 |
create table t1(a int not null primary key, b int) engine=innodb; |
| 42 |
create table t2(a int, b int, constraint a foreign key a (a) references t1(a), |
| 43 |
constraint a foreign key a (a) references t1(b)) engine=innodb; |
| 44 |
ERROR HY000: Can't create table `test`.`t2` (errno: 150 "Foreign key constraint is incorrectly formed") |
| 45 |
show warnings; |
| 46 |
Level Code Message |
| 47 |
Error 1005 Can't create table `test`.`t2` (errno: 150 "Foreign key constraint is incorrectly formed") |
| 48 |
Warning 1215 Cannot add foreign key constraint for `t2` |
| 49 |
create table t2(a int, b int, constraint a foreign key a (a) references t1(a)) engine=innodb; |
| 50 |
alter table t2 add constraint b foreign key (b) references t2(b); |
| 51 |
ERROR HY000: Can't create table `test`.`t2` (errno: 150 "Foreign key constraint is incorrectly formed") |
| 52 |
show warnings; |
| 53 |
Level Code Message |
| 54 |
Warning 150 Alter table `test`.`t2` with foreign key `b` constraint failed. There is no index in the referenced table where the referenced columns appear as the first columns. |
| 55 |
Error 1005 Can't create table `test`.`t2` (errno: 150 "Foreign key constraint is incorrectly formed") |
| 56 |
Warning 1215 Cannot add foreign key constraint for `t2` |
| 57 |
drop table t2, t1; |
| 58 |
create table t1 (f1 integer primary key) engine=innodb; |
| 59 |
alter table t1 add constraint c1 foreign key (f1) references t11(f1); |
| 60 |
ERROR HY000: Can't create table `test`.`t1` (errno: 150 "Foreign key constraint is incorrectly formed") |
| 61 |
show warnings; |
| 62 |
Level Code Message |
| 63 |
Warning 150 Alter table `test`.`t1` with foreign key `c1` constraint failed. Referenced table `test`.`t11` not found in the data dictionary. |
| 64 |
Error 1005 Can't create table `test`.`t1` (errno: 150 "Foreign key constraint is incorrectly formed") |
| 65 |
Warning 1215 Cannot add foreign key constraint for `t1` |
| 66 |
drop table t1; |
| 67 |
create temporary table t1(a int not null primary key, b int, key(b)) engine=innodb; |
| 68 |
create temporary table t2(a int, foreign key(a) references t1(a)) engine=innodb; |
| 69 |
ERROR HY000: Can't create table `test`.`t2` (errno: 150 "Foreign key constraint is incorrectly formed") |
| 70 |
show warnings; |
| 71 |
Level Code Message |
| 72 |
Warning 150 Create table `mysqld.1`.`t2` with foreign key constraint failed. Referenced table `mysqld.1`.`t1` not found in the data dictionary close to foreign key(a) references t1(a)) engine=innodb. |
| 73 |
Error 1005 Can't create table `test`.`t2` (errno: 150 "Foreign key constraint is incorrectly formed") |
| 74 |
Warning 1215 Cannot add foreign key constraint |
| 75 |
alter table t1 add foreign key(b) references t1(a); |
| 76 |
ERROR HY000: Can't create table `test`.`#sql-temporary` (errno: 150 "Foreign key constraint is incorrectly formed") |
| 77 |
show warnings; |
| 78 |
Level Code Message |
| 79 |
Warning 150 Alter table `mysqld.1`.`t1` with foreign key constraint failed. Referenced table `mysqld.1`.`t1` not found in the data dictionary close to foreign key(b) references t1(a). |
| 80 |
Error 1005 Can't create table `test`.`#sql-temporary` (errno: 150 "Foreign key constraint is incorrectly formed") |
| 81 |
Warning 1215 Cannot add foreign key constraint |
| 82 |
create temporary table t2(a int, foreign key(a) references t1(a)) engine=innodb; |
| 83 |
ERROR HY000: Can't create table `test`.`t2` (errno: 150 "Foreign key constraint is incorrectly formed") |
| 84 |
show warnings; |
| 85 |
Level Code Message |
| 86 |
Warning 150 Create table `test`.`t2` with foreign key constraint failed. Temporary tables can't have foreign key constraints. |
| 87 |
Error 1005 Can't create table `test`.`t2` (errno: 150 "Foreign key constraint is incorrectly formed") |
| 88 |
Warning 1215 Cannot add foreign key constraint for `t2` |
| 89 |
alter table t1 add foreign key(b) references t1(a); |
| 90 |
ERROR HY000: Can't create table `test`.`t1` (errno: 150 "Foreign key constraint is incorrectly formed") |
| 91 |
show warnings; |
| 92 |
Level Code Message |
| 93 |
Warning 150 Alter table `test`.`t1` with foreign key constraint failed. Temporary tables can't have foreign key constraints. |
| 94 |
Error 1005 Can't create table `test`.`t1` (errno: 150 "Foreign key constraint is incorrectly formed") |
| 95 |
Warning 1215 Cannot add foreign key constraint for `t1` |
| 96 |
drop table t1; |
| 97 |
create table t1(a int not null primary key, b int, key(b)) engine=innodb; |
| 98 |
alter table t1 add foreign key(a,b) references t1(a); |
| 99 |
ERROR 42000: Incorrect foreign key definition for 'foreign key without name': Key reference and table reference don't match |
| 100 |
show warnings; |
| 101 |
Level Code Message |
| 102 |
Error 1239 Incorrect foreign key definition for 'foreign key without name': Key reference and table reference don't match |
| 103 |
drop table t1; |
| 104 |
create table t1(a int not null primary key, b int, key(b)) engine=innodb; |
| 105 |
alter table t1 add foreign key(a) references t1(a,b); |
| 106 |
ERROR 42000: Incorrect foreign key definition for 'foreign key without name': Key reference and table reference don't match |
| 107 |
show warnings; |
| 108 |
Level Code Message |
| 109 |
Error 1239 Incorrect foreign key definition for 'foreign key without name': Key reference and table reference don't match |
| 110 |
drop table t1; |
| 111 |
create table t1 (f1 integer not null primary key) engine=innodb; |
| 112 |
alter table t1 add constraint c1 foreign key (f1) references t1(f1) on update set null; |
| 113 |
ERROR HY000: Can't create table `test`.`t1` (errno: 150 "Foreign key constraint is incorrectly formed") |
| 114 |
show warnings; |
| 115 |
Level Code Message |
| 116 |
Warning 150 Alter table `test`.`t1` with foreign key `c1` constraint failed. You have defined a SET NULL condition but column 'f1' is defined as NOT NULL. |
| 117 |
Error 1005 Can't create table `test`.`t1` (errno: 150 "Foreign key constraint is incorrectly formed") |
| 118 |
Warning 1215 Cannot add foreign key constraint for `t1` |
| 119 |
create table t2(a int not null, foreign key(a) references t1(f1) on delete set null) engine=innodb; |
| 120 |
ERROR HY000: Can't create table `test`.`t2` (errno: 150 "Foreign key constraint is incorrectly formed") |
| 121 |
show warnings; |
| 122 |
Level Code Message |
| 123 |
Warning 150 Create table `test`.`t2` with foreign key (a) constraint failed. You have defined a SET NULL condition but column 'a' is defined as NOT NULL. |
| 124 |
Error 1005 Can't create table `test`.`t2` (errno: 150 "Foreign key constraint is incorrectly formed") |
| 125 |
Warning 1215 Cannot add foreign key constraint for `t2` |
| 126 |
drop table t1; |
| 127 |
create table t1 (id int not null primary key, f1 int, f2 int, key(f1)) engine=innodb; |
| 128 |
create table t2(a char(20), key(a), foreign key(a) references t1(f1)) engine=innodb; |
| 129 |
ERROR HY000: Can't create table `test`.`t2` (errno: 150 "Foreign key constraint is incorrectly formed") |
| 130 |
show warnings; |
| 131 |
Level Code Message |
| 132 |
Warning 150 Create table `test`.`t2` with foreign key (a) constraint failed. Field type or character set for column 'a' does not match referenced column 'f1'. |
| 133 |
Error 1005 Can't create table `test`.`t2` (errno: 150 "Foreign key constraint is incorrectly formed") |
| 134 |
Warning 1215 Cannot add foreign key constraint for `t2` |
| 135 |
drop table t1; |