gpt4 book ai didi

MySQL 外键错误

转载 作者:太空宇宙 更新时间:2023-11-03 12:32:51 28 4
gpt4 key购买 nike

我想创建一个数据库并将其与两个数据库连接。但是我不知道当我创建第二个数据库(time_shift 表)的外键时,它总是导致错误 150;

下面是表outlet的结构:
Table Outlet

这是表 time_shift 的结构:
Table time_shift

这是创建新表 tide_cart 的查询:

create table `tide_chart` (
`id` int(10) not null auto_increment primary key,
`date` date null,
`outletId` int(11) not null,
`timeShiftId` int(11) not null,
`value` varchar(255) not null,

unique (`date`, `outletId`, `timeShiftId`),
foreign key (`outletId`) references `outlet`(`id`)
ON update cascade ON delete cascade,
foreign key (`timeShiftId`) references `time_shift`(`id`)
ON update cascade ON delete cascade
) engine=innoDB;

请向我解释一下,为什么在尝试使外键连接到表 time_shift 时出现错误?


更新:为outlettime_shift 添加转储导出结构表:

CREATE TABLE `outlet` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(255) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=5 ;

CREATE TABLE `time_shift` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`time_start` time NOT NULL,
`time_end` time NOT NULL,
`is_active` tinyint(4) NOT NULL DEFAULT '1',
`ref_area` int(11) NOT NULL DEFAULT '1',
PRIMARY KEY (`id`),
KEY `ref_area` (`ref_area`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=7 ;

最佳答案

您需要为表使用 InnoDB 引擎。 time_shift 正在使用 MyISAM。

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

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