gpt4 book ai didi

MySQL innodb 外键

转载 作者:行者123 更新时间:2023-11-29 23:23:20 26 4
gpt4 key购买 nike

为什么这个sql不会创建外键?

DROP TABLE IF EXISTS `flow_people`;
CREATE TABLE `flow_people` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`active` enum('0','1') COLLATE utf8_unicode_ci DEFAULT '0',
`created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`token` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,
`unixtime` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,
`modified` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
`company_name` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
`salutation` varchar(4) COLLATE utf8_unicode_ci DEFAULT NULL,
`first_name` varchar(20) COLLATE utf8_unicode_ci NOT NULL,
`middle_name` varchar(20) COLLATE utf8_unicode_ci DEFAULT NULL,
`last_name` varchar(20) COLLATE utf8_unicode_ci NOT NULL,
`dob` date NOT NULL,
`cams` decimal(7,0) NOT NULL,
`location_id` int(8) NOT NULL,
`people_type` int(8) NOT NULL COMMENT 'flow_people_types',
`comment` longtext COLLATE utf8_unicode_ci,
PRIMARY KEY (`id`),
FOREIGN KEY (`people_type`) REFERENCES flow_people_types(`id`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB AUTO_INCREMENT=1666 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

表 flow_people_types 存在,它有一个 ID 列。

我认为我在这里遗漏了一些基本的东西,问题是什么?

最佳答案

检查此链接 MySQL Foreign Keys :

试试这个:

DROP TABLE IF EXISTS `flow_people`;
CREATE TABLE `flow_people` (
`id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
`active` ENUM('0','1') COLLATE utf8_unicode_ci DEFAULT '0',
`created` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`token` VARCHAR(50) COLLATE utf8_unicode_ci DEFAULT NULL,
`unixtime` VARCHAR(50) COLLATE utf8_unicode_ci DEFAULT NULL,
`modified` TIMESTAMP NOT NULL DEFAULT '0000-00-00 00:00:00',
`company_name` VARCHAR(255) COLLATE utf8_unicode_ci DEFAULT NULL,
`salutation` VARCHAR(4) COLLATE utf8_unicode_ci DEFAULT NULL,
`first_name` VARCHAR(20) COLLATE utf8_unicode_ci NOT NULL,
`middle_name` VARCHAR(20) COLLATE utf8_unicode_ci DEFAULT NULL,
`last_name` VARCHAR(20) COLLATE utf8_unicode_ci NOT NULL,
`dob` DATE NOT NULL,
`cams` DECIMAL(7,0) NOT NULL,
`location_id` INT(8) NOT NULL,
`people_type` INT(8) NOT NULL COMMENT 'flow_people_types',
`comment` LONGTEXT COLLATE utf8_unicode_ci,
PRIMARY KEY (`id`),
KEY `FK_flow_people_FPT` (`people_type`),
CONSTRAINT `FK_flow_people_FPT` FOREIGN KEY (`people_type`) REFERENCES flow_people_types(`id`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=INNODB AUTO_INCREMENT=1666 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

关于MySQL innodb 外键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27140740/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com