0
我們有以下腳本:mysql#1215 - 無法添加外鍵約束 - 但爲什麼?
CREATE TABLE `dataBodyChanges` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT ,
`numberOfContainers` int(11) NOT NULL ,
`quantityPerContainer` int(11) NOT NULL ,
`grossWeight` double NOT NULL ,
`comment` varchar(1000) NOT NULL ,
`file` int(10) unsigned DEFAULT NULL ,
`user` int(10) unsigned NOT NULL ,
`dataBodyId` int(10) unsigned NOT NULL ,
`created_at` timestamp NULL DEFAULT NULL ,
`updated_at` timestamp NULL DEFAULT NULL ,
PRIMARY KEY (`id`) ,
KEY `databodychanges_databodyid_foreign` (`dataBodyId`) ,
CONSTRAINT `databodychanges_databodyid_foreign` FOREIGN KEY (`dataBodyId`) REFERENCES `dataBodies` (`id`)
) ENGINE = InnoDB AUTO_INCREMENT =1113 DEFAULT CHARSET = utf8;
與MySQL輸出:
1215 - 不能添加外鍵約束
其他表:
使用材料;
CREATE TABLE `dataBodies` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`partNumber` varchar(8) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`totalOrderQuantity` varchar(9) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`containerPart` varchar(8) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`numberOfContainers` varchar(9) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`quantityPerContainer` varchar(9) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`kanbanNumber` varchar(4) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`matHandlingCode` varchar(12) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`grossWeight` varchar(9) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`partRemarks` varchar(18) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`AI11Z` varchar(50) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`AI12Z` varchar(50) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`AI13Z` varchar(50) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`AI14Z` varchar(50) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`AI15Z` varchar(50) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`AI16Z` varchar(50) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`AI17Z` varchar(50) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`filler` varchar(163) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`dataHeaderId` int(10) unsigned DEFAULT NULL,
`created_at` timestamp NULL DEFAULT NULL,
`updated_at` timestamp NULL DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `databodies_dataheaderid_foreign` (`dataHeaderId`),
CONSTRAINT `databodies_dataheaderid_foreign` FOREIGN KEY (`dataHeaderId`) REFERENCES `dataHeaders` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=1113 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
我們不知道爲什麼....
任何人可以請幫誰是大師嗎? 提前謝謝!
請不要看charset的錯誤!他們已經被糾正了! – Erkman