我正在尝试运行 5 个创建表语句。其中 3 个在我声明的外键上工作正常,但是表'generalweather'和'userreg'抛出错误 1005,我知道这与我的外键不匹配有关。我一直在寻找错误,但我无法在任何地方找到它。这两个创建表语句有什么问题?(我的默认架构名为“tester”)
CREATE TABLE `coastal` (
`Date` varchar(50) NOT NULL,
`Time` varchar(50) NOT NULL DEFAULT '',
`AM/PM` varchar(45) NOT NULL,
`Location` varchar(50) NOT NULL DEFAULT '',
`Tide Description` varchar(50) DEFAULT NULL,
`Estimated Swell(ft)` int(11) DEFAULT NULL,
`Wind Speed(mph)` int(11) DEFAULT NULL,
`Wind Direction` varchar(45) DEFAULT NULL,
`Visibility (%)` varchar(50) DEFAULT NULL,
PRIMARY KEY (`Date`,`Time`,`Location`,`AM/PM`),
CONSTRAINT `coastalFK`
FOREIGN KEY (Date, Time, Location, `AM/PM`)
REFERENCES tester.locations (Date, Time, Location, `AM/PM`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
INDEX `DateFK_idx` (`Date` ASC) ,
INDEX `TimeFK_idx` (`Time` ASC) ,
INDEX `AM/PMFK_idx` (`AM/PM` ASC) ,
INDEX `LocationFK_idx` (`Location` ASC)
);
CREATE TABLE `generalweather` (
`Date` varchar(50) NOT NULL,
`Location` varchar(50) NOT NULL,
`ClimateDescription` varchar(50) NOT NULL DEFAULT '',
`Average Temperature(F)` int(11) DEFAULT NULL,
`Elevation(ft)` varchar(50) DEFAULT NULL,
`Recommended Activity` varchar(50) DEFAULT NULL,
PRIMARY KEY (`Date`,`Location`,`ClimateDescription`),
CONSTRAINT `generalweatherFK`
FOREIGN KEY (Date, Location)
REFERENCES tester.locations (Date, Location)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
INDEX `DateFK_idx` (`Date` ASC) ,
INDEX `LocationFK_idx` (`Location` ASC)
);
CREATE TABLE `locations` (
`Date` varchar(50) NOT NULL DEFAULT '',
`Time` varchar(50) NOT NULL DEFAULT '',
`AM/PM` varchar(45) NOT NULL,
`Location` varchar(50) NOT NULL DEFAULT '',
`Location Type` varchar(50) DEFAULT NULL,
`Temperature (F)` varchar(45) DEFAULT NULL,
PRIMARY KEY (`Date`,`Time`,`Location`,`AM/PM`)
);
CREATE TABLE `precipitation` (
`Date` varchar(50) NOT NULL,
`Time` varchar(50) NOT NULL DEFAULT '',
`AM/PM` varchar(45) NOT NULL,
`Location` varchar(50) NOT NULL DEFAULT '',
`Precipitation Chance (%)` text,
`Wind Speed(mph)` int(11) DEFAULT NULL,
`Wind Direction` varchar(50) DEFAULT NULL,
`Visibility (%)` varchar(50) DEFAULT NULL,
`Humidity (%)` varchar(50) DEFAULT NULL,
PRIMARY KEY (`Date`,`Time`,`AM/PM`,`Location`),
CONSTRAINT `DateFK`
FOREIGN KEY (Date, Time, Location, `AM/PM`)
REFERENCES tester.locations (Date, Time, Location, `AM/PM`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
INDEX `DateFK_idx` (`Date` ASC) ,
INDEX `TimeFK_idx` (`Time` ASC) ,
INDEX `AM/PMFK_idx` (`AM/PM` ASC) ,
INDEX `LocationFK_idx` (`Location` ASC)
);
CREATE TABLE `userreg` (
`User Name` varchar(50) NOT NULL DEFAULT '',
`Real Name` varchar(50) DEFAULT NULL,
`Email address` varchar(50) DEFAULT 'NONE ON FILE',
`Location` varchar(50) NOT NULL,
PRIMARY KEY (`User Name`),
CONSTRAINT `userregFK`
FOREIGN KEY (`Location`)
REFERENCES tester.locations (`Location`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
INDEX `LocationFK_idx` (`Location` ASC)
);