Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql 无法添加外键约束,为什么?_Mysql - Fatal编程技术网

Mysql 无法添加外键约束,为什么?

Mysql 无法添加外键约束,为什么?,mysql,Mysql,好吧,我在这里真的很沮丧,我似乎无法发现问题 问题是,我试图创建表Vinter和Sommar,但是MYSQL 不允许我这样做,因为“错误代码:1215.无法添加外键约束” “ 代码如下: CREATE TABLE Stuga( stugaNr int unsigned AUTO_INCREMENT PRIMARY KEY, stugaAdress char(60), nrOfBeds int, nrOfRooms int ); DROP TABLE Customer; CREATE TABL

好吧,我在这里真的很沮丧,我似乎无法发现问题

问题是,我试图创建表Vinter和Sommar,但是MYSQL 不允许我这样做,因为“错误代码:1215.无法添加外键约束” “

代码如下:

CREATE TABLE Stuga(
stugaNr int unsigned AUTO_INCREMENT PRIMARY KEY,
stugaAdress char(60),
nrOfBeds int,
nrOfRooms int
);

DROP TABLE Customer;

CREATE TABLE Customer(
    customerNr int unsigned AUTO_INCREMENT primary key,
    lastName char(30),
    totalPassengers int
);

DROP TABLE Bokning;

CREATE TABLE Bokning(
    orderID int(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
    stugaNr int UNSIGNED,
    customerNr int UNSIGNED,
    passengerNr int UNSIGNED,
    datum int,
    FOREIGN KEY (stugaNr) REFERENCES Stuga(stugaNr),
    FOREIGN KEY (customerNr) REFERENCES Customer(customerNr)
);

DROP TABLE Sommar;

CREATE TABLE Sommar(
    orderID int,
    totalPassengers int,
    sNr int primary key,
    benLangd int unsigned,
    huvudOmkrets int unsigned,
    cykelTyp char(30),
    FOREIGN KEY (orderID) REFERENCES Bokning(orderID)
);

DROP TABLE Vinter;

CREATE TABLE Vinter(
    orderID int,
    totalPassengers int,
    vNr int primary key,
    skidLangd int unsigned,
    stavLangd int unsigned,
    hjalm char(20),
    skoStorlek int unsigned,
    FOREIGN KEY (orderID) REFERENCES Bokning(orderID)
);

我刚把它贴出来就看到了。忘记在其他orderID上添加“int(6)UNSIGNED”

无论如何谢谢你:D