MySQL中间表错误代码1005(150)无法创建外键

时间:2015-07-13 17:49:49

标签: mysql

我有两个表,我想加入一个中间表,用于多对多的关系

第一张表是预订

CREATE TABLE booking (
    bookingID INT NOT NULL AUTO_INCREMENT,
    customerID INT,
    runID INT,
    startDate DATE,
    endDate DATE,
    dateBookedOn  TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    PRIMARY KEY (bookingID),
    INDEX idx_start (startDate),
    INDEX idx_end (endDate),
    FOREIGN KEY (runID) REFERENCES Run(RunID),
    FOREIGN KEY (customerID) REFERENCES customer(CustomerID));

第二个是狗

CREATE TABLE dog(
    DogID int(6) NOT NULL,
    DogName varchar(15),
    medicalID int (6),
    Gender character(1) check(gender in ('m', 'f')),
    Age int(2),
    Breed varchar(15),
    size character (1) check(size in ('s', 'm', 'l')),
    primary key (DogID));

和中间表如下,给出错误1005(150),对于bookingID的外键有问题。但无法看到问题。欢迎任何帮助。

CREATE TABLE isBooked(
    BookingID int not null,
    DogID int not null,
    foreign key (DogID) references Dog(dogID),
    foreign key (BookingID) references Booking(BookingID));

0 个答案:

没有答案