Mysql 无法添加外键约束错误1215

Mysql 无法添加外键约束错误1215,mysql,sql,Mysql,Sql,我正在使用Workbench 6.0,遇到了一个令人沮丧的问题,我是SQl新手,希望尽可能简单。我相信我的表顺序正确,可以添加约束,除了我的票证表之外,我不知道如何找到有问题的外键 CREATE TABLE IF NOT EXISTS ACTION_TYPE ( ActionCode int primary key, Description char(50) not null )ENGINE=InnoDB; CREATE TABLE IF NOT EXISTS OFFICER ( Person

我正在使用Workbench 6.0,遇到了一个令人沮丧的问题,我是SQl新手,希望尽可能简单。我相信我的表顺序正确,可以添加约束,除了我的票证表之外,我不知道如何找到有问题的外键

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;
创建表(如果不存在)操作类型(
ActionCode int主键,
说明字符(50)不为空
)引擎=InnoDB;
如果不存在,则创建表(
PersonnelNo int主键,
OfficerName字符(50)不为空,
公务员姓名字符(50)不为空
)引擎=InnoDB;
如果驱动程序不存在,则创建表(
DriverLicenseNo int主键,
DriverLastName字符(50)不为空,
DriverFirstName字符(50)不为空,
DriverAddress字符(50)不为空,
DriverCity字符(50)不为空,
DriverProv字符(50)不为空,
DriverPostalCode varchar(6)不为空,
DriverGender字符(1)不为空,
DriverBarthDate日期不为空
)引擎=InnoDB;
如果不存在已注册的\u所有者,则创建表(
RegOwnerID int主键自动递增,
RegownerName字符(50)不为空,
RegOwnerFName字符(50)不为空,
RegOwnerAddress字符(50)不为空,
RegOwnerCity字符(50)不为空,
RegOwnerProv字符(50)不为空,
RegOwnerPostalCode varchar(6)不为空
)引擎=InnoDB;
如果不存在车辆类型,则创建表格(
车辆类型int主键,
车辆描述字符(50)不为空
)引擎=InnoDB;
如果车辆不存在,则创建表格(
车辆许可int主键,
ProvinceIssuited字符(2)不为空,
VehicleYear int不为空,
VehicleMake char(10)不为空,
VehicleType int不为空,
索引(车辆类型),
外键(车辆类型)
参考车辆类型(车辆类型)
)引擎=InnoDB;

创建表,如果不存在票证(DriverLicenseNo上的拼写错误在票证表中)
DriversLicenseNo在DRIVER表中

您看到的确切错误是什么?错误代码:1215.无法在DriversLicenseNo上添加外键约束0.031秒拼写错误在票证表中没有在DriversLicenseNo在DRIVER表中非常感谢您找到了这个错误,抱歉浪费时间,我真的没有看到这个错误,即使我扫描并扫描了s佩林,该睡觉了。