对于我的生活,我无法找出为什么MySQL不喜欢这句话:
CREATE TABLE IF NOT EXISTS personnel
(
id INTEGER AUTO_INCREMENT PRIMARY KEY,
firstname VARCHAR(30) NOT NULL,
lastname VARCHAR(30) NOT NULL,
role VARCHAR(50) NOT NULL,
line_manager INTEGER NULL,
FOREIGN KEY (role) REFERENCES roles(name)
ON DELETE CASCADE
ON UPDATE CASCADE,
FOREIGN KEY (line_manager) REFERENCES personnel(id)
ON DELETE CASCADE
ON UPDATE CASCADE
) ENGINE=InnoDB;
插入此项后,MySQL的结果输出为ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'DELETE CASCADE
UPDATE CASCADE,
FOREIGN KEY (line_manager) REFERENCES personnel(id)
' at line 10
。
有人能说出我做错了吗?
答案 0 :(得分:2)
1) table roles must have same **engine** that is InnoDB
2) the length of both column that is personnel(role) and roles(name) must be **equal**
3) column roles(name) must be **primary key**
检查一下,我认为它会起作用