gpt4 book ai didi

MySQL:错误号:150 "Foreign key constraint is incorrectly formed"

转载 作者:行者123 更新时间:2023-11-30 21:53:44 26 4
gpt4 key购买 nike

我正在尝试创建这些表,但遇到了这个错误

Error Code: 1005. Can't create table estadisticas.tbl008_phase_competition (errno: 150 "Foreign key constraint is incorrectly formed")

当我尝试创建 tbl008_phase_competition ...

create table if not exists `tbl015_seasons` (
`id` smallint(4) unsigned not null auto_increment,
`id_competition` smallint(2) unsigned not null,
`description` varchar(100) not null,
primary key(`id`),
foreign key (`id_competition`) references `tbl001_competition` (`id`)
)ENGINE = InnoDB;

create table if not exists `tbl012_phase` (
`id` smallint(4) unsigned not null auto_increment,
`name` varchar(100) not null,
primary key (`id`)
)ENGINE = InnoDB;

create table if not exists `tbl008_phase_competition` (
`id_season` smallint(4) unsigned not null,
`id_phase` smallint(4) unsigned not null,
`year` int unsigned not null,
primary key (`id_season`, `id_phase`),
foreign key (`id_season`) references `tbl015_seasons` (`id`),
foreign key (`id_phase`) references `tbl012_phase` (`id`)
)ENGINE = InnoDB;

我做错了什么?

最佳答案

请不要在此表中声明主键并检查:

create table if not exists `tbl008_phase_competition` (
`id_season` smallint(4) unsigned not null,
`id_phase` smallint(4) unsigned not null,
`year` int unsigned not null,
primary key (`id_season`, `id_phase`), // remove this line
foreign key (`id_season`) references `tbl015_seasons` (`id`),
foreign key (`id_phase`) references `tbl012_phase` (`id`)
)ENGINE = InnoDB;

关于MySQL:错误号:150 "Foreign key constraint is incorrectly formed",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46095690/

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