我在尝试创建接下来的两个表时遇到了这个非常不明显的错误,我认为它只是一个错误拼写或缺少逗号,但似乎无法找到它。有人可以查看我的代码,看看我在这里做错了吗?
错误
#1005 - Can't create table './cbw222_inspections/Melons.frm' (errno: 150)
LATEST FOREIGN KEY ERROR
------------------------
120305 12:33:51 Error in foreign key constraint of table temp/Melons:
FOREIGN KEY (`ShipperID`) REFERENCES Shipper(`ShipperID`) ON DELETE CASCADE ON UPDATE CASCADE,
FOREIGN KEY (`InspectorID`) REFERENCES Inspectors(`InspectorID`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=UTF8 AUTO_INCREMENT=1:
Cannot resolve table name close to:
(`ShipperID`) ON DELETE CASCADE ON UPDATE CASCADE,
FOREIGN KEY (`InspectorID`) REFERENCES Inspectors(`InspectorID`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=UTF8 AUTO_INCREMENT=1
SQL
DROP TABLE IF EXISTS `Customer`;
CREATE TABLE `Customer` (
`CustomerID` INT UNSIGNED AUTO_INCREMENT,
`Customer_Number` VARCHAR(70),
`Customer_Name` VARCHAR(70),
`Website` VARCHAR(255),
`Logo` VARCHAR(100),
PRIMARY KEY(`CustomerID`)
) ENGINE=InnoDB DEFAULT CHARSET=UTF8 AUTO_INCREMENT=1;
DROP TABLE IF EXISTS `Reports`;
CREATE TABLE `Reports` (
`ReportID` INT UNSIGNED AUTO_INCREMENT,
`Role` VARCHAR(70),
`Region` VARCHAR(70),
`Inpection_Type` VARCHAR(70),
`CustomerID` INT UNSIGNED NOT NULL,
`Report_Date` DATE NOT NULL DEFAULT '0000-00-00',
`Order_Date` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
`Customer_Name` VARCHAR(100),
`Customer_Division` VARCHAR(70),
`Memo` VARCHAR(255),
`Billing_Key` VARCHAR(70),
PRIMARY KEY(`ReportID`),
FOREIGN KEY (`CustomerID`) REFERENCES Customer(`CustomerID`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=UTF8 AUTO_INCREMENT=1;
DROP TABLE IF EXISTS `Customer_Contact`;
CREATE TABLE `Customer_Contact` (
`ContactID` INT UNSIGNED AUTO_INCREMENT,
`CustomerID` INT UNSIGNED NOT NULL,
`Division` VARCHAR(100),
`Contact` VARCHAR(100),
`Address` VARCHAR(255),
`Phone` VARCHAR(100),
`Fax` VARCHAR(100),
`Email` VARCHAR(100),
`Mobile` VARCHAR(100),
PRIMARY KEY(`ContactID`),
CONSTRAINT FOREIGN KEY (`CustomerID`) REFERENCES Customer(`CustomerID`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=UTF8 AUTO_INCREMENT=1;
DROP TABLE IF EXISTS `Inspectors`;
CREATE TABLE `Inspectors` (
`InspectorID` INT UNSIGNED AUTO_INCREMENT,
`Name` VARCHAR(70),
`Phone` VARCHAR(70),
`Address` VARCHAR(255),
`Email` VARCHAR(100),
`Fax` VARCHAR(70),
PRIMARY KEY(`InspectorID`)
) ENGINE=InnoDB DEFAULT CHARSET=UTF8 AUTO_INCREMENT=1;
DROP TABLE IF EXISTS `Lists`;
CREATE TABLE `Lists` (
`ListID` INT UNSIGNED AUTO_INCREMENT,
`Commodity` VARCHAR(70),
`Region` VARCHAR(70),
`Shipper` VARCHAR(100),
`Variety` VARCHAR(70),
`Style` VARCHAR(70),
`Label` VARCHAR(70),
`Pack_Date` DATE NOT NULL default '0000-00-00',
`Grower_Lot` VARCHAR(70),
`Berry_Size1` VARCHAR(5),
`Berry_Size2` VARCHAR(5),
`Berry_Size3` VARCHAR(5),
`Berry_Size4` VARCHAR(5),
`Bunch_Count1` VARCHAR(5),
`Bunch_Count2` VARCHAR(5),
`Color1` VARCHAR(15),
`Color2` VARCHAR(15),
`Rating` VARCHAR(25),
`InspectorID` INT UNSIGNED NOT NULL,
`Comments` VARCHAR(255),
PRIMARY KEY(`ListID`),
FOREIGN KEY (`InspectorID`) REFERENCES Inspectors(`InspectorID`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=UTF8 AUTO_INCREMENT=1;
DROP TABLE IF EXISTS `Melons`;
CREATE TABLE `Melons` (
`MelonsID` INT UNSIGNED AUTO_INCREMENT,
`ReportID` INT UNSIGNED NOT NULL,
`ShipperID` INT UNSIGNED NOT NULL,
`Status` ENUM('0','1','2') NOT NULL DEFAULT 0,
`PO` VARCHAR(15),
`Location` VARCHAR(75),
`InspectorID` INT UNSIGNED NOT NULL,
`Commodity` VARCHAR(25),
`Count` VARCHAR(20),
`Size` VARCHAR(20),
`Label` VARCHAR(100),
`Variety` VARCHAR(25),
`Pack_Date` DATE NOT NULL default '0000-00-00',
`Grower_Lot` VARCHAR(25),
`Color1` VARCHAR(15),
`Color2` VARCHAR(15),
`Ground_Color1` VARCHAR(15),
`Ground_Color2` VARCHAR(15),
`Texture1` VARCHAR(5),
`Texture2` VARCHAR(5),
`Scar1` VARCHAR(5),
`Scar2` VARCHAR(5),
`Solidity1` VARCHAR(5),
`Solidity2` VARCHAR(5),
`Cut1` VARCHAR(5),
`Cut2` VARCHAR(5),
`Sugar_Brix1` VARCHAR(5),
`Sugar_Brix2` VARCHAR(5),
`Rating` VARCHAR(35),
`Comments` VARCHAR(255),
PRIMARY KEY(`MelonsID`),
FOREIGN KEY (`ReportID`) REFERENCES Reports(`ReportID`) ON DELETE CASCADE ON UPDATE CASCADE,
FOREIGN KEY (`ShipperID`) REFERENCES Shipper(`ShipperID`) ON DELETE CASCADE ON UPDATE CASCADE,
FOREIGN KEY (`InspectorID`) REFERENCES Inspectors(`InspectorID`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=UTF8 AUTO_INCREMENT=1;
DROP TABLE IF EXISTS `Melon_Photos`;
CREATE TABLE `Melon_Photos` (
`PhotoID` INT UNSIGNED AUTO_INCREMENT,
`MelonsID` INT UNSIGNED NOT NULL,
`Photo` VARCHAR(70),
`Caption` VARCHAR(255),
`Catalog` VARCHAR(50),
PRIMARY KEY(`MelonsID`),
FOREIGN KEY (`MelonsID`) REFERENCES Melons(`MelonsID`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=UTF8 AUTO_INCREMENT=1;
DROP TABLE IF EXISTS `Table_Grapes`;
CREATE TABLE `Table_Grapes` (
`GrapeID` INT UNSIGNED AUTO_INCREMENT,
`ReportID` INT UNSIGNED NOT NULL,
`ShipperID` INT UNSIGNED NOT NULL,
`Status` ENUM('0','1','2') NOT NULL DEFAULT 0,
`PO` VARCHAR(15),
`Location` VARCHAR(75),
`InspectorID` INT UNSIGNED NOT NULL,
`Commodity` VARCHAR(25),
`Pack_Type` VARCHAR(35),
`Count` VARCHAR(20),
`Label` VARCHAR(100),
`Variety` VARCHAR(25),
`Style` VARCHAR(35),
`Pack_Date` DATE NOT NULL default '0000-00-00',
`Grower_Lot` VARCHAR(25),
`Berry_Sizing1` VARCHAR(15),
`Berry_Sizing2` VARCHAR(15),
`Berry_Sizing3` VARCHAR(15),
`Berry_Sizing4` VARCHAR(15),
`Bunch_Count1` VARCHAR(15),
`Bunch_Count2` VARCHAR(15),
`Color1` VARCHAR(15),
`Color2` VARCHAR(15),
`Stem_Cond1` VARCHAR(15),
`Stem_Cond2` VARCHAR(15),
`Stem_Cond3` VARCHAR(15),
`Shatter1` VARCHAR(5),
`Shatter2` VARCHAR(5),
`Decay_Count1` VARCHAR(15),
`Decay_Count2` VARCHAR(15),
`Sugar_Brix1` VARCHAR(5),
`Sugar_Brix2` VARCHAR(5),
`Rating` VARCHAR(35),
`Comments` VARCHAR(255),
PRIMARY KEY(`GrapeID`),
FOREIGN KEY (`ReportID`) REFERENCES Reports(`ReportID`) ON DELETE CASCADE ON UPDATE CASCADE,
FOREIGN KEY (`ShipperID`) REFERENCES Shipper(`ShipperID`) ON DELETE CASCADE ON UPDATE CASCADE,
FOREIGN KEY (`InspectorID`) REFERENCES Inspectors(`InspectorID`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=UTF8 AUTO_INCREMENT=1;
DROP TABLE IF EXISTS `Grape_Photos`;
CREATE TABLE `Grape_Photos` (
`PhotoID` INT UNSIGNED AUTO_INCREMENT,
`GrapeID` INT UNSIGNED NOT NULL,
`Photo` VARCHAR(70),
`Caption` VARCHAR(255),
`Catalog` VARCHAR(50),
PRIMARY KEY(`GrapeID`),
FOREIGN KEY (`GrapeID`) REFERENCES Grape(`GrapeID`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=UTF8 AUTO_INCREMENT=1;
DROP TABLE IF EXISTS `Berries`;
CREATE TABLE `Berries` (
`BerryID` INT UNSIGNED AUTO_INCREMENT,
`ReportID` INT UNSIGNED NOT NULL,
`ShipperID` INT UNSIGNED NOT NULL,
`Status` ENUM('0','1','2') NOT NULL DEFAULT 0,
`PO` VARCHAR(15),
`Location` VARCHAR(75),
`InspectorID` INT UNSIGNED NOT NULL,
`Commodity` VARCHAR(25),
`Count` VARCHAR(20),
`Size` VARCHAR(20),
`Label` VARCHAR(100),
`Variety` VARCHAR(25),
`Pack_Date` DATE NOT NULL default '0000-00-00',
`Grower_Lot` VARCHAR(25),
`Color1` VARCHAR(15),
`Color2` VARCHAR(15),
`Berry_Sizing1` VARCHAR(15),
`Berry_Sizing2` VARCHAR(15),
`Berry_Sizing3` VARCHAR(15),
`Berry_Sizing4` VARCHAR(15),
`Firmness1` VARCHAR(5),
`Firmness2` VARCHAR(5),
`Scar1` VARCHAR(5),
`Scar2` VARCHAR(5),
`Bruise_Count1` VARCHAR(5),
`Bruise_Count2` VARCHAR(5),
`Decay_Count1` VARCHAR(5),
`Decay_Count2` VARCHAR(5),
`Sugar_Brix1` VARCHAR(5),
`Sugar_Brix2` VARCHAR(5),
`Rating` VARCHAR(35),
`Comments` VARCHAR(255),
PRIMARY KEY(`BerryID`),
FOREIGN KEY (`ReportID`) REFERENCES Reports(`ReportID`) ON DELETE CASCADE ON UPDATE CASCADE,
FOREIGN KEY (`ShipperID`) REFERENCES Shipper(`ShipperID`) ON DELETE CASCADE ON UPDATE CASCADE,
FOREIGN KEY (`InspectorID`) REFERENCES Inspectors(`InspectorID`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=UTF8 AUTO_INCREMENT=1;
DROP TABLE IF EXISTS `Berries_Photos`;
CREATE TABLE `Berries_Photos` (
`PhotoID` INT UNSIGNED AUTO_INCREMENT,
`BerryID` INT UNSIGNED NOT NULL,
`Photo` VARCHAR(70),
`Caption` VARCHAR(255),
`Catalog` VARCHAR(50),
PRIMARY KEY(`BerryID`),
FOREIGN KEY (`BerryID`) REFERENCES Berries(`BerryID`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=UTF8 AUTO_INCREMENT=1;
DROP TABLE IF EXISTS `Citrus`;
CREATE TABLE `Citrus` (
`CitrusID` INT UNSIGNED AUTO_INCREMENT,
`ReportID` INT UNSIGNED NOT NULL,
`ShipperID` INT UNSIGNED NOT NULL,
`Status` ENUM('0','1','2') NOT NULL DEFAULT 0,
`PO` VARCHAR(15),
`Location` VARCHAR(75),
`InspectorID` INT UNSIGNED NOT NULL,
`Commodity` VARCHAR(25),
`Count` VARCHAR(20),
`Size` VARCHAR(20),
`Label` VARCHAR(100),
`Variety` VARCHAR(25),
`Pack_Date` DATE NOT NULL default '0000-00-00',
`Grower_Lot` VARCHAR(25),
`Color1` VARCHAR(15),
`Color2` VARCHAR(15),
`Texture1` VARCHAR(15),
`Texture2` VARCHAR(15),
`Puff1` VARCHAR(15),
`Puff2` VARCHAR(15),
`Scar1` VARCHAR(5),
`Scar2` VARCHAR(5),
`Solidity1` VARCHAR(15),
`Solidity2` VARCHAR(15),
`Green1` VARCHAR(15),
`Green2` VARCHAR(15),
`Sugar_Brix1` VARCHAR(5),
`Sugar_Brix2` VARCHAR(5),
`Rating` VARCHAR(35),
`Comments` VARCHAR(255),
PRIMARY KEY(`CitrusID`),
FOREIGN KEY (`ReportID`) REFERENCES Reports(`ReportID`) ON DELETE CASCADE ON UPDATE CASCADE,
FOREIGN KEY (`ShipperID`) REFERENCES Shipper(`ShipperID`) ON DELETE CASCADE ON UPDATE CASCADE,
FOREIGN KEY (`InspectorID`) REFERENCES Inspectors(`InspectorID`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=UTF8 AUTO_INCREMENT=1;
DROP TABLE IF EXISTS `Citrus_Photos`;
CREATE TABLE `Citrus_Photos` (
`PhotoID` INT UNSIGNED AUTO_INCREMENT,
`CitrusID` INT UNSIGNED NOT NULL,
`Photo` VARCHAR(70),
`Caption` VARCHAR(255),
`Catalog` VARCHAR(50),
PRIMARY KEY(`CitrusID`),
FOREIGN KEY (`CitrusID`) REFERENCES Citrus(`CitrusID`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=UTF8 AUTO_INCREMENT=1;
DROP TABLE IF EXISTS `Tree_Fruit`;
CREATE TABLE `Tree_Fruit` (
`TreeID` INT UNSIGNED AUTO_INCREMENT,
`ReportID` INT UNSIGNED NOT NULL,
`ShipperID` INT UNSIGNED NOT NULL,
`Status` ENUM('0','1','2') NOT NULL DEFAULT 0,
`PO` VARCHAR(15),
`Location` VARCHAR(75),
`InspectorID` INT UNSIGNED NOT NULL,
`Commodity` VARCHAR(25),
`Count` VARCHAR(20),
`Size` VARCHAR(20),
`Label` VARCHAR(100),
`Variety` VARCHAR(25),
`Pack_Date` DATE NOT NULL default '0000-00-00',
`Grower_Lot` VARCHAR(25),
`Color1` VARCHAR(15),
`Color2` VARCHAR(15),
`Ground_Color1` VARCHAR(15),
`Ground_Color2` VARCHAR(15),
`Solidity1` VARCHAR(15),
`Solidity2` VARCHAR(15),
`Scar1` VARCHAR(5),
`Scar2` VARCHAR(5),
`Bruise_Count1` VARCHAR(5),
`Bruise_Count2` VARCHAR(5),
`Decay_Count1` VARCHAR(5),
`Decay_Count2` VARCHAR(5),
`Sugar_Brix1` VARCHAR(5),
`Sugar_Brix2` VARCHAR(5),
`Rating` VARCHAR(35),
`Comments` VARCHAR(255),
PRIMARY KEY(`TreeID`),
FOREIGN KEY (`ReportID`) REFERENCES Reports(`ReportID`) ON DELETE CASCADE ON UPDATE CASCADE,
FOREIGN KEY (`ShipperID`) REFERENCES Shipper(`ShipperID`) ON DELETE CASCADE ON UPDATE CASCADE,
FOREIGN KEY (`InspectorID`) REFERENCES Inspectors(`InspectorID`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=UTF8 AUTO_INCREMENT=1;
DROP TABLE IF EXISTS `Tree_Fruit_Photos`;
CREATE TABLE `Tree_Fruit_Photos` (
`PhotoID` INT UNSIGNED AUTO_INCREMENT,
`TreeID` INT UNSIGNED NOT NULL,
`Photo` VARCHAR(70),
`Caption` VARCHAR(255),
`Catalog` VARCHAR(50),
PRIMARY KEY(`TreeID`),
FOREIGN KEY (`TreeID`) REFERENCES Tree_Fruit(`TreeID`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=UTF8 AUTO_INCREMENT=1;
DROP TABLE IF EXISTS `Lot`;
CREATE TABLE `Lot` (
`LotID` INT UNSIGNED AUTO_INCREMENT,
`ReportID` INT UNSIGNED NOT NULL,
`ShipperID` INT UNSIGNED NOT NULL,
`Status` ENUM('0','1','2') NOT NULL DEFAULT 0,
`PO` VARCHAR(15),
`Location` VARCHAR(75),
`InspectorID` INT UNSIGNED NOT NULL,
`Commodity` VARCHAR(25),
`Pack_Type` VARCHAR(35),
`Count` VARCHAR(20),
`Label` VARCHAR(100),
`Variety` VARCHAR(25),
`Style` VARCHAR(35),
`Pack_Date` DATE NOT NULL default '0000-00-00',
`Grower_Lot` VARCHAR(25),
`Berry_Sizing1` VARCHAR(15),
`Berry_Sizing2` VARCHAR(15),
`Berry_Sizing3` VARCHAR(15),
`Berry_Sizing4` VARCHAR(15),
`Bunch_Count1` VARCHAR(15),
`Bunch_Count2` VARCHAR(15),
`Color1` VARCHAR(15),
`Color2` VARCHAR(15),
`Stem_Cond1` VARCHAR(15),
`Stem_Cond2` VARCHAR(15),
`Stem_Cond3` VARCHAR(15),
`Shatter1` VARCHAR(5),
`Shatter2` VARCHAR(5),
`Splits1` VARCHAR(5),
`Splits2` VARCHAR(5),
`Decay_Count1` VARCHAR(15),
`Decay_Count2` VARCHAR(15),
`Wet_Sticky1` VARCHAR(15),
`Wet_Sticky2` VARCHAR(15),
`Overall_Quality` VARCHAR(25),
`Sugar_Brix1` VARCHAR(5),
`Sugar_Brix2` VARCHAR(5),
`Overall_Condition` VARCHAR(25),
`Rating` VARCHAR(35),
`Comments` VARCHAR(255),
PRIMARY KEY(`LotID`),
FOREIGN KEY (`ReportID`) REFERENCES Reports(`ReportID`) ON DELETE CASCADE ON UPDATE CASCADE,
FOREIGN KEY (`ShipperID`) REFERENCES Shipper(`ShipperID`) ON DELETE CASCADE ON UPDATE CASCADE,
FOREIGN KEY (`InspectorID`) REFERENCES Inspectors(`InspectorID`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=UTF8 AUTO_INCREMENT=1;
DROP TABLE IF EXISTS `Lot_Photos`;
CREATE TABLE `Lot_Photos` (
`PhotoID` INT UNSIGNED AUTO_INCREMENT,
`LotID` INT UNSIGNED NOT NULL,
`Photo` VARCHAR(70),
`Caption` VARCHAR(255),
`Catalog` VARCHAR(50),
PRIMARY KEY(`LotID`),
FOREIGN KEY (`LotID`) REFERENCES Lot(`LotID`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=UTF8 AUTO_INCREMENT=1;
DROP TABLE IF EXISTS `Shipper`;
CREATE TABLE `Shipper` (
`ShipperID` INT UNSIGNED AUTO_INCREMENT,
`Shipper_Name` VARCHAR(70),
`Shipper_Number` VARCHAR(70),
`Website` VARCHAR(255),
PRIMARY KEY(`ShipperID`)
) ENGINE=InnoDB DEFAULT CHARSET=UTF8 AUTO_INCREMENT=1;
DROP TABLE IF EXISTS `Shipper_Contact`;
CREATE TABLE `Shipper_Contact` (
`SContactID` INT UNSIGNED AUTO_INCREMENT,
`ShipperID` INT UNSIGNED NOT NULL,
`CustomerID` INT UNSIGNED NOT NULL,
`Division` VARCHAR(100),
`Contact` VARCHAR(100),
`Address` VARCHAR(255),
`Phone` VARCHAR(100),
`Fax` VARCHAR(100),
`Email` VARCHAR(100),
`Mobile` VARCHAR(100),
PRIMARY KEY(`SContactID`),
CONSTRAINT FOREIGN KEY (`CustomerID`) REFERENCES Customer(`CustomerID`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT FOREIGN KEY (`ShipperID`) REFERENCES Shipper(`ShipperID`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=UTF8 AUTO_INCREMENT=1;
DROP TABLE IF EXISTS `Shipper_Label`;
CREATE TABLE `Shipper_Label` (
`ShipperLabelID` INT UNSIGNED AUTO_INCREMENT,
`ShipperID` INT UNSIGNED NOT NULL,
`Shipper_Name` VARCHAR(70),
`Shipper_Label` VARCHAR(255),
PRIMARY KEY(`ShipperLabelID`),
CONSTRAINT FOREIGN KEY (`ShipperID`) REFERENCES Shipper(`ShipperID`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=UTF8 AUTO_INCREMENT=1;
答案 0 :(得分:0)
这是外键错误。
运行此命令:
SHOW ENGINE INNODB STATUS\G
然后在输出中查找“LATEST FOREIGN KEY ERROR”以查看错误的详细信息。
<强>更新强> 现在您已经显示了确切的错误,这是一个解决方案。
在运行脚本之前设置此环境变量,它允许您在父表之前创建子表:
SET FOREIGN_KEY_CHECKS = 0;
答案 1 :(得分:0)
Melons表引用了一个尚未创建的表(在行的下方创建)外键的引用,以及其他较小的错误