#1005-错误代码:150“外键约束格式不正确”正在实现数据库

时间:2019-05-12 11:42:24

标签: mysql sql

我正在尝试将MySQL Workbench中的数据库实现为PHPMyadmin。但是,我尝试了很多,但无法正常工作。告诉我无法创建某个表,因为外键约束格式不正确。希望你们中的任何人看到我的代码有什么问题。

这是我的代码:

-- MySQL dump 10.13  Distrib 8.0.16, for Win64 (x86_64)
--
-- Host: localhost    Database: db-website
-- ------------------------------------------------------
-- Server version   8.0.15

/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
 SET NAMES utf8 ;
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;

--
-- Table structure for table `tblcategory`
--

DROP TABLE IF EXISTS `tblcategory`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
 SET character_set_client = utf8 ;
CREATE TABLE `tblcategory` (
  `ID` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `strName` varchar(45) NOT NULL,
  `strDescription` varchar(100) NOT NULL,
  PRIMARY KEY (`ID`),
  UNIQUE KEY `ID_UNIQUE` (`ID`),
  UNIQUE KEY `strName_UNIQUE` (`strName`),
  UNIQUE KEY `strDescription_UNIQUE` (`strDescription`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `tblcategory`
--

LOCK TABLES `tblcategory` WRITE;
/*!40000 ALTER TABLE `tblcategory` DISABLE KEYS */;
INSERT INTO `tblcategory` VALUES (1,'Beers','Beers - description...'),(2,'Wines','Wines - description...'),(3,'Liquors','Liquors - description...');
/*!40000 ALTER TABLE `tblcategory` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `tblproduct`
--

DROP TABLE IF EXISTS `tblproduct`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
 SET character_set_client = utf8 ;
CREATE TABLE `tblproduct` (
  `ID` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `strName` varchar(45) NOT NULL,
  `decPrice` decimal(10,2) unsigned NOT NULL,
  `intVolume` decimal(10,2) unsigned NOT NULL,
  `strDescription` varchar(100) NOT NULL,
  `idProductCategory` int(10) unsigned NOT NULL,
  `idProductSubCategory` int(10) unsigned NOT NULL,
  PRIMARY KEY (`ID`),
  UNIQUE KEY `ID_UNIQUE` (`ID`),
  UNIQUE KEY `strName_UNIQUE` (`strName`),
  UNIQUE KEY `strDescription_UNIQUE` (`strDescription`),
  KEY `ProductSubCategory_idx` (`idProductSubCategory`),
  KEY `ProductCategory_idx` (`idProductCategory`),
  CONSTRAINT `ProductCategory` FOREIGN KEY (`idProductCategory`) REFERENCES `tblcategory` (`ID`) ON DELETE CASCADE ON UPDATE CASCADE,
  CONSTRAINT `ProductSubCategory` FOREIGN KEY (`idProductSubCategory`) REFERENCES `tblsubcategory` (`ID`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `tblproduct`
--

LOCK TABLES `tblproduct` WRITE;
/*!40000 ALTER TABLE `tblproduct` DISABLE KEYS */;
INSERT INTO `tblproduct` VALUES (1,'Heineken H41',6.99,2.00,'Heineken H41 Lager',1,2),(2,'G7 sauvignon blanc',5.00,0.75,'G7 sauvignon blanc White Wine ',2,12),(3,'Jack Daniel\'s Tennessee',26.99,0.70,'Jack Daniel\'s Tennessee Whiskey',3,21);
/*!40000 ALTER TABLE `tblproduct` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `tblsubcategory`
--

DROP TABLE IF EXISTS `tblsubcategory`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
 SET character_set_client = utf8 ;
CREATE TABLE `tblsubcategory` (
  `ID` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `strName` varchar(45) NOT NULL,
  `strDescription` varchar(45) NOT NULL,
  `idCategory` int(10) unsigned NOT NULL,
  PRIMARY KEY (`ID`),
  UNIQUE KEY `ID_UNIQUE` (`ID`),
  UNIQUE KEY `strName_UNIQUE` (`strName`),
  KEY `SubCategory-Category_idx` (`idCategory`),
  CONSTRAINT `SubCategory-Category` FOREIGN KEY (`idCategory`) REFERENCES `tblcategory` (`ID`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=22 DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `tblsubcategory`
--

LOCK TABLES `tblsubcategory` WRITE;
/*!40000 ALTER TABLE `tblsubcategory` DISABLE KEYS */;
INSERT INTO `tblsubcategory` VALUES (1,'Ale','Description...',1),(2,'Lager','Description...',1),(3,'Pilsner','Description...',1),(4,'Stout','Description...',1),(5,'Porter','Description...',1),(6,'Bock','Description...',1),(7,'Weissbier','Description...',1),(8,'Lambic','Description...',1),(9,'Kölsch','Description...',1),(10,'Malt Liquor','Description...',1),(11,'Red Wine','Description...',2),(12,'White Wine','Description...',2),(13,'Rosé Wine','Description...',2),(14,'Sparkling Wine','Description...',2),(15,'Fortified Wine','Description...',2),(16,'Gin','Description...',3),(17,'Rum','Description...',3),(18,'Brandy','Description...',3),(19,'Tequila','Description...',3),(20,'Vodka','Description...',3),(21,'Whiskey','Description...',3);
/*!40000 ALTER TABLE `tblsubcategory` ENABLE KEYS */;
UNLOCK TABLES;
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;

/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;

-- Dump completed on 2019-05-12 13:15:55

0 个答案:

没有答案