[英]InnoDB MySql Error 1215 Cannot add foreign key constraint / even after removing cascade obligations on DELETE
I'm trying to add foreign keys to my two tables Problem and File. 我正在尝试将外键添加到两个表“问题”和“文件”中。 These are the CREATE queries.
这些是CREATE查询。 And both tables are created successfully:
并成功创建了两个表:
CREATE TABLE lpsolve.tbl_file (
id INT(11) NOT NULL AUTO_INCREMENT,
problem_id INT(11) DEFAULT NULL,
title VARCHAR(255) DEFAULT NULL,
description VARCHAR(255) DEFAULT NULL,
type VARCHAR(255) DEFAULT NULL,
create_time DATETIME DEFAULT NULL,
PRIMARY KEY (id)
)
ENGINE = INNODB
AUTO_INCREMENT = 1
CHARACTER SET latin1
COLLATE latin1_swedish_ci;
CREATE TABLE lpsolve.tbl_probem (
id INT(11) NOT NULL AUTO_INCREMENT,
title VARCHAR(255) DEFAULT NULL,
description VARCHAR(255) DEFAULT NULL,
create_time DATETIME DEFAULT NULL,
number_of_files INT(11) DEFAULT NULL,
PRIMARY KEY (id)
)
ENGINE = INNODB
AUTO_INCREMENT = 1
CHARACTER SET latin1
COLLATE latin1_swedish_ci;
But when I try to add the following constraint I get the Error 1215 Error. 但是,当我尝试添加以下约束时,出现错误1215错误。 This is the add constraint query:
这是添加约束查询:
ALTER TABLE tbl_file
ADD CONSTRAINT fk_problem_file
FOREIGN KEY (problem_id)
REFERENCES tbl_problem(id)
ON DELETE CASCADE
ON UPDATE RESTRICT
The query does not work even by removing the ON DELETE CASCADE
and ON UPDATE RESTRICT
either. 即使删除了
ON DELETE CASCADE
和ON UPDATE RESTRICT
,查询也不起作用。 There are a couple of similar problems mentioned in Stack Overflow but they did not answer my problem unfortunately. 堆栈溢出中提到了两个类似的问题,但是不幸的是它们并没有解决我的问题。
Error message: 错误信息:
Cannot add foreign key constraint
The table name is tbl_probem
表名称是
tbl_probem
CREATE TABLE lpsolve.tbl_probem (
but the ALTER command is trying to reference a table: tbl_problem
但是ALTER命令试图引用一个表:
tbl_problem
REFERENCES tbl_problem(id)
Delete l
from problem
to solve this problem. 从
problem
删除l
以解决此问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.