无法添加外键约束错误1215

时间:2013-11-29 05:06:50

标签: mysql sql

我正在使用Workbench 6.0并且遇到令人沮丧的问题我是SQl的新手,并希望此时尽可能保持这个简单,我相信我的表是正确订购的,除了我的TICKET表之外还要添加约束,不知道如何找到外键有问题。

CREATE TABLE IF NOT EXISTS ACTION_TYPE (
ActionCode int primary key,
Description char(50) not null
)ENGINE=InnoDB;

CREATE TABLE IF NOT EXISTS OFFICER (
PersonnelNo int primary key,
OfficerLName char(50) not null,
OfficerFName char(50) not null
)ENGINE=InnoDB;

CREATE TABLE IF NOT EXISTS DRIVER (
DriverLicenseNo int primary key,
DriverLastName char(50) not null,
DriverFirstName char(50) not null,
DriverAddress char(50) not null,
DriverCity char(50) not null,
DriverProv char(50) not null,
DriverPostalCode varchar(6) not null,
DriverGender char(1) not null,
DriverBirthDate Date not null
)ENGINE=InnoDB;

CREATE TABLE IF NOT EXISTS REGISTERED_OWNER (
RegOwnerID int primary key auto_increment,
RegOwnerLName char(50) not null,
RegOwnerFName char(50) not null,
RegOwnerAddress char(50) not null,
RegOwnerCity char(50) not null,
RegOwnerProv char(50) not null,
RegOwnerPostalCode varchar(6) not null
)ENGINE=InnoDB;


CREATE TABLE IF NOT EXISTS VEHICLE_TYPE (
VehicleType int primary key,
VehicleDescription char(50) not null
)ENGINE=InnoDB;

CREATE TABLE IF NOT EXISTS VEHICLE (
VehicleLicense int primary key,
ProvinceIssued char(2) not null,
VehicleYear int not null,
VehicleMake char(10) not null,
VehicleType int not null,
index (VehicleType),
foreign key (VehicleType)
    references VEHICLE_TYPE (VehicleType)
)ENGINE=InnoDB;

CREATE TABLE IF NOT EXISTS TICKET (      <-----this table calling the error
TicketNo int primary key auto_increment,
TicketDateTime datetime not null,
TicketLocationCity char(50) not null,
TicketLocationProv char(50) not null,
TicketLocationRoad char(50) not null,

PersonnelNo int not null,
VehicleLicense int not null,
ActionCode int not null,
RegOwnerID int not null,
DriversLicenseNo int not null,

index (PersonnelNo),
foreign key (PersonnelNo)
    references OFFICER (PersonnelNo),

index (VehicleLicense),
foreign key (VehicleLicense)
    references VEHICLE (VehicleLicense),

index (ActionCode),
foreign key (ActionCode)
    references ACTION_TYPE (ActionCode),

index (RegOwnerID),
foreign key (RegOwnerID)
    references REGISTERED_OWNER (RegOwnerID),

index (DriversLicenseNo),
foreign key (DriversLicenseNo)
    references DRIVER (DriversLicenseNo)

)ENGINE=InnoDB;

CREATE TABLE IF NOT EXISTS VIOLATION_TYPE (
ViolationCode int primary key auto_increment,
ViolationDesc char(50) not null,
ViolationCurrFineAmt int not null
)ENGINE=InnoDB;

CREATE TABLE IF NOT EXISTS VIOLATION (

ViolationNo int primary key auto_increment,
TicketNo int not null,
ViolationCode int not null,
AppliedFineAmount int not null,
index (TicketNo),
foreign key (TicketNo)
    references TICKET (TicketNo),
index (ViolationCode),
foreign key (ViolationCode)
    references VIOLATION_TYPE (ViolationCode)
)ENGINE=InnoDB;

1 个答案:

答案 0 :(得分:1)

TICKET表中的DriverLicenseNo拼写错误 DriversLicenseNo在DRIVER表中