I can't import my SQL tables from Adminer to MySQL Workbench without getting error: ERROR 1215 (HY000) at line 9: Cannot add foreign key constraint
I can't import my SQL tables from Adminer to MySQL Workbench without getting error: ERROR 1215 (HY000) at line 9: Cannot add foreign key constraint
我正在尝试将我的 NodeJS 应用程序部署到 Heroku,并使用这些参数导出我的 MariaDB SQL 表:
Format: SQL
Tables: DROP+CREATE |Triggers
但是,当我导入它们时,我得到了模糊的错误:第 9 行的错误 1215 (HY000):无法添加外键约束。这是我的 SQL 导出的一部分:
-- Adminer 4.6.3 MySQL dump
SET NAMES utf8;
SET time_zone = '+00:00';
SET NAMES utf8mb4;
DROP TABLE IF EXISTS `Govt_answers`;
CREATE TABLE `Govt_answers` (
`Answer_id` int(3) unsigned NOT NULL AUTO_INCREMENT,
`Question_id` int(2) unsigned NOT NULL,
`Correct` bit(1) NOT NULL,
`Answer_prompt` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_520_ci NOT NULL,
PRIMARY KEY (`Answer_id`),
KEY `Question_id` (`Question_id`),
CONSTRAINT `Govt_answers_ibfk_1` FOREIGN KEY (`Question_id`) REFERENCES `Govt_questions` (`Question_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
DROP TABLE IF EXISTS `Govt_choice_response`;
CREATE TABLE `Govt_choice_response` (
`Quiz_id` int(2) unsigned NOT NULL,
`Question_id` int(2) unsigned NOT NULL,
`Answer_id` int(3) unsigned NOT NULL,
`Correct` bit(1) DEFAULT NULL,
`Time_start` datetime DEFAULT NULL,
`Time_stop` datetime DEFAULT NULL,
`Student_id` int(4) unsigned NOT NULL,
KEY `Quiz_id` (`Quiz_id`),
KEY `Question_id` (`Question_id`),
KEY `Answer_id` (`Answer_id`),
KEY `Student_id` (`Student_id`),
CONSTRAINT `Govt_choice_response_ibfk_1` FOREIGN KEY (`Answer_id`) REFERENCES `Govt_answers` (`Answer_id`),
CONSTRAINT `Govt_choice_response_ibfk_2` FOREIGN KEY (`Question_id`) REFERENCES `Govt_questions` (`Question_id`),
CONSTRAINT `Govt_choice_response_ibfk_4` FOREIGN KEY (`Quiz_id`) REFERENCES `Govt_quizes` (`Quiz_id`),
CONSTRAINT `Govt_choice_response_ibfk_5` FOREIGN KEY (`Question_id`) REFERENCES `Govt_questions` (`Question_id`),
CONSTRAINT `Govt_choice_response_ibfk_6` FOREIGN KEY (`Answer_id`) REFERENCES `Govt_answers` (`Answer_id`),
CONSTRAINT `Govt_choice_response_ibfk_7` FOREIGN KEY (`Student_id`) REFERENCES `Govt_profiles` (`Student_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
....etc
我在 Raspberry Pi 上的外部服务器 运行 上尝试了 SHOW ENGINE INNODB STATUS,但它没有提供任何关于外键问题的见解。
知道问题出在哪里吗?
我通过禁用外键检查然后再启用来解决这个问题。
这个.
我正在尝试将我的 NodeJS 应用程序部署到 Heroku,并使用这些参数导出我的 MariaDB SQL 表:
Format: SQL
Tables: DROP+CREATE |Triggers
但是,当我导入它们时,我得到了模糊的错误:第 9 行的错误 1215 (HY000):无法添加外键约束。这是我的 SQL 导出的一部分:
-- Adminer 4.6.3 MySQL dump
SET NAMES utf8;
SET time_zone = '+00:00';
SET NAMES utf8mb4;
DROP TABLE IF EXISTS `Govt_answers`;
CREATE TABLE `Govt_answers` (
`Answer_id` int(3) unsigned NOT NULL AUTO_INCREMENT,
`Question_id` int(2) unsigned NOT NULL,
`Correct` bit(1) NOT NULL,
`Answer_prompt` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_520_ci NOT NULL,
PRIMARY KEY (`Answer_id`),
KEY `Question_id` (`Question_id`),
CONSTRAINT `Govt_answers_ibfk_1` FOREIGN KEY (`Question_id`) REFERENCES `Govt_questions` (`Question_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
DROP TABLE IF EXISTS `Govt_choice_response`;
CREATE TABLE `Govt_choice_response` (
`Quiz_id` int(2) unsigned NOT NULL,
`Question_id` int(2) unsigned NOT NULL,
`Answer_id` int(3) unsigned NOT NULL,
`Correct` bit(1) DEFAULT NULL,
`Time_start` datetime DEFAULT NULL,
`Time_stop` datetime DEFAULT NULL,
`Student_id` int(4) unsigned NOT NULL,
KEY `Quiz_id` (`Quiz_id`),
KEY `Question_id` (`Question_id`),
KEY `Answer_id` (`Answer_id`),
KEY `Student_id` (`Student_id`),
CONSTRAINT `Govt_choice_response_ibfk_1` FOREIGN KEY (`Answer_id`) REFERENCES `Govt_answers` (`Answer_id`),
CONSTRAINT `Govt_choice_response_ibfk_2` FOREIGN KEY (`Question_id`) REFERENCES `Govt_questions` (`Question_id`),
CONSTRAINT `Govt_choice_response_ibfk_4` FOREIGN KEY (`Quiz_id`) REFERENCES `Govt_quizes` (`Quiz_id`),
CONSTRAINT `Govt_choice_response_ibfk_5` FOREIGN KEY (`Question_id`) REFERENCES `Govt_questions` (`Question_id`),
CONSTRAINT `Govt_choice_response_ibfk_6` FOREIGN KEY (`Answer_id`) REFERENCES `Govt_answers` (`Answer_id`),
CONSTRAINT `Govt_choice_response_ibfk_7` FOREIGN KEY (`Student_id`) REFERENCES `Govt_profiles` (`Student_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
....etc
我在 Raspberry Pi 上的外部服务器 运行 上尝试了 SHOW ENGINE INNODB STATUS,但它没有提供任何关于外键问题的见解。 知道问题出在哪里吗?
我通过禁用外键检查然后再启用来解决这个问题。
这个