语法中可能有什么问题?

时间:2018-02-18 12:22:20

标签: mysql sql

我试图放入外键的表,它给了我这个错误(#1005 - Can't create table databasemodule.transactions (errno: 150 "Foreign key constraint is incorrectly formed") (Details…)):

CREATE TABLE Transactions(
    TsID INT NOT NULL,
    BookingDate TIMESTAMP NOT NULL,
    DepartureDate TIMESTAMP NOT NULL,
    Passenger INT NOT NULL,
    Flight INT NOT NULL,
    TYPE BLOB NOT NULL,
    Employee INT NOT NULL,
    Charges INT NOT NULL,
    Discount INT NOT NULL,
    CONSTRAINT pks PRIMARY KEY(TsID),
    CONSTRAINT FOREIGN KEY(Charges) REFERENCES Charges(ChID),
    CONSTRAINT FOREIGN KEY(Employee) REFERENCES Employee(EmpID),
    CONSTRAINT FOREIGN KEY(Passenger) REFERENCES Passenger(PsID),
    CONSTRAINT FOREIGN KEY(Discount) REFERENCES Discounts(DsID) 
);

另外两个表作为例子:

CREATE TABLE Charges(
    ChID INT NOT NULL,
    Title VARCHAR(50) NOT NULL,
    Amount INT(255) NOT NULL,
    Description VARCHAR(255) NOT NULL,
    CONSTRAINT pks PRIMARY KEY(ChID)
);

CREATE TABLE Discounts(
    DsID INT NOT NULL,
    Title VARCHAR(50) NOT NULL,
    Amount INT(255) NOT NULL,
    Description VARCHAR(255) NOT NULL,
    PRIMARY KEY(DsID)
);

如果我只留下4个中的一个外键,它可以完美地工作。在phpmyadmin上使用InnoDb,UTF-8

0 个答案:

没有答案