ErrorNo 150 mySQL

时间:2018-03-13 11:29:15

标签: mysql

当我尝试在同一个表中创建两个外键时遇到此问题  我如何解决它&谢谢

create table employee(
employeeNumber INT (11) primary key,

);


create table projects(

projectNumber INT(11) primary key ,

);

create table workat(
wemployeeNumber INT(11),
wprojectNUmber INT (11),
primary key (wemployeeNumber,wprojectNUmber),    
FOREIGN key workat(wemployeeNumber) references employee(employeeNumber), 
FOREIGN key workat(wprojectNUmber) references projects(projectNumber) 

);

1 个答案:

答案 0 :(得分:1)

您的FOREIGN KEY语法对我而言,我不知道您为什么要在workat中包含该定义。试试这个版本:

CREATE TABLE workat (
    wemployeeNumber INT(11),
    wprojectNUmber INT(11),
    PRIMARY KEY (wemployeeNumber, wprojectNumber),    
    FOREIGN KEY (wemployeeNumber) REFERENCES employee (employeeNumber), 
    -- projects, not project
    FOREIGN KEY (wprojectNUmber)  REFERENCES projects (projectNumber) 
);

这是一个演示,显示您的代码在进行上述更改后进行编译:

Demo