0

对于我的生活,我不知道为什么 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.

谁能建议我做错了什么?

4

1 回答 1

2

嘿,我检查了你的 mysql 查询并且它有效我认为你应该检查以下约束

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**

只需检查这些东西,我认为它会起作用

于 2013-07-18T12:11:08.623 回答