CREATE TABLE `db`.`employee_meeting` (
`employee_id` BIGINT(20) NOT NULL,
`meeting_id` BIGINT(20) NOT NULL,
PRIMARY KEY (`employee_id`, `meeting_id`),
INDEX `FK_meeting`(`meeting_id`),
CONSTRAINT `FK_employee` FOREIGN KEY `FK_employee` (`employee_id`)
REFERENCES `employee` (`employee_id`)
ON DELETE RESTRICT
ON UPDATE RESTRICT,
CONSTRAINT `FK_meeting` FOREIGN KEY `FK_meeting` (`meeting_id`)
REFERENCES `meeting` (`meeting_id`)
ON DELETE RESTRICT
ON UPDATE RESTRICT
答案 0 :(得分:1)
可能是因为您的其他两个表尚不存在。以下工作正常:
CREATE TABLE employee (
employee_id BIGINT(20) NOT NULL,
PRIMARY KEY (employee_id)
);
CREATE TABLE meeting (
meeting_id BIGINT(20) NOT NULL,
PRIMARY KEY (meeting_id)
);
CREATE TABLE employee_meeting (
employee_id BIGINT(20) NOT NULL,
meeting_id BIGINT(20) NOT NULL,
PRIMARY KEY (employee_id, meeting_id),
INDEX FK_meeting(meeting_id),
CONSTRAINT FK_employee
FOREIGN KEY FK_employee (employee_id)
REFERENCES employee (employee_id)
ON DELETE RESTRICT
ON UPDATE RESTRICT,
CONSTRAINT FK_meeting
FOREIGN KEY FK_meeting (meeting_id)
REFERENCES meeting (meeting_id)
ON DELETE RESTRICT
ON UPDATE RESTRICT
)
答案 1 :(得分:0)
Error 150 deals with foreign key errors。准备好在编写模式时经常遇到它们,因为它们很容易制作。
要询问引擎问题所在,请运行以下命令:
SHOW ENGINE INNODB STATUS
这将显示最新的错误。
如果这没有用,请按照以下一般提示进行操作:
通常列定义是让我兴奋的原因。因此,请确保父表包含BIGINT(20)
,并且没有UNSIGNED
或其他类型,例如INT(10)
。