我正在尝试在具有三个外键的 MySQL 数据库中创建一个表,但出现错误。这个错误对我来说并不明显,可以使用第三方检查。
CREATE TABLE `main_message`(
id INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
strat_key INT NULL,
task INT NULL,
user INT,
comment VARCHAR(255) NOT NULL,
datestamp DATETIME,
FOREIGN KEY strat_key REFERENCES prod_main_strategicdirection(id) ON UPDATE CASCADE ON DELETE CASCADE,
FOREIGN KEY task REFERENCES main_task(id) ON UPDATE CASCADE ON DELETE CASCADE,
FOREIGN KEY user REFERENCES prod_auth_user(id) ON UPDATE CASCADE ON DELETE CASCADE,
) ENGINE = INNODB;
根据输出,我收到错误消息
You have an error in your SQL syntax; check the manual that corresponds to your
MariaDB server version for the right syntax to use near ' foreign key strat_key
references prod_main_strategicdirection(id) on update cas'
就在第一个外键声明之后
FOREIGN KEY strat_key REFERENCES prod_main_strategicdirection(id)
但我看不出什么会导致错误。