2015-07-29 04:58:45 +02:00
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,
2015-07-31 07:52:24 +02:00
CONSTRAINT mytest FOREIGN KEY (c) REFERENCES t1(id),
2015-07-29 04:58:45 +02:00
CONSTRAINT test FOREIGN KEY (b) REFERENCES t2 (id)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
2015-08-03 22:09:43 +02:00
ERROR HY000: Can't create table `test`.`t2` (errno: 121 "Duplicate key on write or update")
2015-07-29 04:58:45 +02:00
show warnings;
Level Code Message
2016-08-12 10:17:45 +02:00
Warning 121 Create or Alter table `test`.`t2` with foreign key constraint failed. Foreign key constraint `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`).
2015-08-03 22:09:43 +02:00
Error 1005 Can't create table `test`.`t2` (errno: 121 "Duplicate key on write or update")
Warning 1022 Can't write; duplicate key in table 't2'
2015-07-29 04:58:45 +02:00
drop table t1;
2015-07-31 07:52:24 +02:00
create table t1(a int) engine=innodb;
create table t2(a int, constraint a foreign key a (a) references t1(a)) engine=innodb;
2015-08-03 22:09:43 +02:00
ERROR HY000: Can't create table `test`.`t2` (errno: 150 "Foreign key constraint is incorrectly formed")
2015-07-31 07:52:24 +02:00
show warnings;
Level Code Message
2015-11-09 08:23:32 +01:00
Warning 150 Create table '`test`.`t2`' with foreign key constraint failed. There is no index in the referenced table where the referenced columns appear as the first columns near ' foreign key a (a) references t1(a)) engine=innodb'.
2015-08-03 22:09:43 +02:00
Error 1005 Can't create table `test`.`t2` (errno: 150 "Foreign key constraint is incorrectly formed")
Warning 1215 Cannot add foreign key constraint
2015-07-31 07:52:24 +02:00
drop table t1;
create table t1(a int not null primary key, b int) engine=innodb;
create table t2(a int, b int, constraint a foreign key a (a) references t1(a),
constraint a foreign key a (a) references t1(b)) engine=innodb;
2015-08-03 22:09:43 +02:00
ERROR HY000: Can't create table `test`.`t2` (errno: 150 "Foreign key constraint is incorrectly formed")
2015-07-31 07:52:24 +02:00
show warnings;
Level Code Message
2015-08-03 22:09:43 +02:00
Error 1005 Can't create table `test`.`t2` (errno: 150 "Foreign key constraint is incorrectly formed")
Warning 1215 Cannot add foreign key constraint
2015-07-31 07:52:24 +02:00
create table t2(a int, b int, constraint a foreign key a (a) references t1(a)) engine=innodb;
alter table t2 add constraint b foreign key (b) references t2(b);
2015-08-03 22:09:43 +02:00
ERROR HY000: Can't create table `test`.`#sql-temporary` (errno: 150 "Foreign key constraint is incorrectly formed")
2015-07-31 07:52:24 +02:00
show warnings;
Level Code Message
2015-11-09 08:23:32 +01:00
Warning 150 Alter table '`test`.`t2`' with foreign key constraint failed. There is no index in the referenced table where the referenced columns appear as the first columns near ' foreign key (b) references t2(b)'.
2015-08-03 22:09:43 +02:00
Error 1005 Can't create table `test`.`#sql-temporary` (errno: 150 "Foreign key constraint is incorrectly formed")
Warning 1215 Cannot add foreign key constraint
2015-07-31 07:52:24 +02:00
drop table t2, t1;
create table t1 (f1 integer primary key) engine=innodb;
alter table t1 add constraint c1 foreign key (f1) references t11(f1);
2015-08-03 22:09:43 +02:00
ERROR HY000: Can't create table `test`.`#sql-temporary` (errno: 150 "Foreign key constraint is incorrectly formed")
2015-07-31 07:52:24 +02:00
show warnings;
Level Code Message
2015-11-09 08:23:32 +01:00
Warning 150 Alter table `test`.`t1` with foreign key constraint failed. Referenced table `test`.`t11` not found in the data dictionary near ' foreign key (f1) references t11(f1)'.
2015-08-03 22:09:43 +02:00
Error 1005 Can't create table `test`.`#sql-temporary` (errno: 150 "Foreign key constraint is incorrectly formed")
Warning 1215 Cannot add foreign key constraint
2015-07-31 07:52:24 +02:00
drop table t1;
create temporary table t1(a int not null primary key, b int, key(b)) engine=innodb;
create temporary table t2(a int, foreign key(a) references t1(a)) engine=innodb;
2015-08-03 22:09:43 +02:00
ERROR HY000: Can't create table `test`.`t2` (errno: 150 "Foreign key constraint is incorrectly formed")
2015-07-31 07:52:24 +02:00
show warnings;
Level Code Message
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.
2015-08-03 22:09:43 +02:00
Error 1005 Can't create table `test`.`t2` (errno: 150 "Foreign key constraint is incorrectly formed")
Warning 1215 Cannot add foreign key constraint
2015-07-31 07:52:24 +02:00
alter table t1 add foreign key(b) references t1(a);
2015-08-03 22:09:43 +02:00
ERROR HY000: Can't create table `test`.`#sql-temporary` (errno: 150 "Foreign key constraint is incorrectly formed")
2015-07-31 07:52:24 +02:00
show warnings;
Level Code Message
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).
2015-08-03 22:09:43 +02:00
Error 1005 Can't create table `test`.`#sql-temporary` (errno: 150 "Foreign key constraint is incorrectly formed")
Warning 1215 Cannot add foreign key constraint
2015-07-31 07:52:24 +02:00
drop table t1;
create table t1(a int not null primary key, b int, key(b)) engine=innodb;
alter table t1 add foreign key(a,b) references t1(a);
2015-08-03 22:09:43 +02:00
ERROR 42000: Incorrect foreign key definition for 'foreign key without name': Key reference and table reference don't match
2015-07-31 07:52:24 +02:00
show warnings;
Level Code Message
2015-08-03 22:09:43 +02:00
Error 1239 Incorrect foreign key definition for 'foreign key without name': Key reference and table reference don't match
2015-07-31 07:52:24 +02:00
drop table t1;
create table t1(a int not null primary key, b int, key(b)) engine=innodb;
alter table t1 add foreign key(a) references t1(a,b);
2015-08-03 22:09:43 +02:00
ERROR 42000: Incorrect foreign key definition for 'foreign key without name': Key reference and table reference don't match
2015-07-31 07:52:24 +02:00
show warnings;
Level Code Message
2015-08-03 22:09:43 +02:00
Error 1239 Incorrect foreign key definition for 'foreign key without name': Key reference and table reference don't match
2015-07-31 07:52:24 +02:00
drop table t1;
create table t1 (f1 integer not null primary key) engine=innodb;
alter table t1 add constraint c1 foreign key (f1) references t1(f1) on update set null;
2015-08-03 22:09:43 +02:00
ERROR HY000: Can't create table `test`.`#sql-temporary` (errno: 150 "Foreign key constraint is incorrectly formed")
2015-07-31 07:52:24 +02:00
show warnings;
Level Code Message
2015-11-09 08:23:32 +01:00
Warning 150 Alter table `test`.`t1` with foreign key constraint failed. You have defined a SET NULL condition but column 'f1' is defined as NOT NULL in ' foreign key (f1) references t1(f1) on update set null' near ' on update set null'.
2015-08-03 22:09:43 +02:00
Error 1005 Can't create table `test`.`#sql-temporary` (errno: 150 "Foreign key constraint is incorrectly formed")
Warning 1215 Cannot add foreign key constraint
2015-07-31 07:52:24 +02:00
create table t2(a int not null, foreign key(a) references t1(f1) on delete set null) engine=innodb;
2015-08-03 22:09:43 +02:00
ERROR HY000: Can't create table `test`.`t2` (errno: 150 "Foreign key constraint is incorrectly formed")
2015-07-31 07:52:24 +02:00
show warnings;
Level Code Message
2015-11-09 08:23:32 +01:00
Warning 150 Create table `test`.`t2` with foreign key constraint failed. You have defined a SET NULL condition but column 'a' is defined as NOT NULL in 'foreign key(a) references t1(f1) on delete set null) engine=innodb' near ' on delete set null) engine=innodb'.
2015-08-03 22:09:43 +02:00
Error 1005 Can't create table `test`.`t2` (errno: 150 "Foreign key constraint is incorrectly formed")
Warning 1215 Cannot add foreign key constraint
2015-07-31 07:52:24 +02:00
drop table t1;
create table t1 (id int not null primary key, f1 int, f2 int, key(f1)) engine=innodb;
create table t2(a char(20), key(a), foreign key(a) references t1(f1)) engine=innodb;
2015-08-03 22:09:43 +02:00
ERROR HY000: Can't create table `test`.`t2` (errno: 150 "Foreign key constraint is incorrectly formed")
2015-07-31 07:52:24 +02:00
show warnings;
Level Code Message
2015-11-09 08:23:32 +01:00
Warning 150 Create table `test`.`t2` with foreign key constraint failed. Field type or character set for column 'a' does not mach referenced column 'f1' near 'foreign key(a) references t1(f1)) engine=innodb'.
2015-08-03 22:09:43 +02:00
Error 1005 Can't create table `test`.`t2` (errno: 150 "Foreign key constraint is incorrectly formed")
Warning 1215 Cannot add foreign key constraint
2015-07-31 07:52:24 +02:00
drop table t1;