gpt4 book ai didi

mysqli : Cannot create MANY to MANY table?

转载 作者:行者123 更新时间:2023-11-29 19:31:27 25 4
gpt4 key购买 nike

我设置了 3 个表。一种是配料。另一个用于膳食,最后一个用于两者之间的交界处引用。然而,每次我尝试为“meal_fk”设置外键时,我都会收到没有定义的索引错误,即使据我所知,它已被索引,或者我将其属性设置为已索引。那么我做错了什么?

enter image description here

enter image description here

enter image description here

编辑:膳食表

enter image description here

成分

Table   Create Table    
ingredients CREATE TABLE `ingredients` (
`ingredient_id` int(6) unsigned NOT NULL AUTO_INCREMENT,
`quanity` int(6) NOT NULL,
`package` int(6) NOT NULL,
`item` varchar(50) DEFAULT NULL,
`cost` decimal(18,2) DEFAULT NULL,
`store` varchar(50) DEFAULT NULL,
`reg_date` timestamp NULL DEFAULT NULL,
PRIMARY KEY (`ingredient_id`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4

膳食

Table   Create Table    
meals CREATE TABLE `meals` (
`meal_id` int(6) unsigned NOT NULL AUTO_INCREMENT,
`ingredients` int(6) NOT NULL,
`meal` varchar(50) NOT NULL,
`cost` decimal(18,2) DEFAULT NULL,
`reg_date` timestamp NULL DEFAULT NULL,
PRIMARY KEY (`meal_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4

JUNCTION 食材餐

Table   Create Table    
junction_ingredients_meals CREATE TABLE `junction_ingredients_meals` (
`junction_id` int(6) NOT NULL,
`ingredient_fk` int(6) NOT NULL,
`meal_fk` int(6) NOT NULL,
PRIMARY KEY (`junction_id`),
KEY `ingredient_fk` (`ingredient_fk`,`meal_fk`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4

最佳答案

啊,我明白了,引用字段需要与引用的字段类型完全相同(除非它们可以为空,即使引用的字段不是空的)。您的问题是您引用的字段是 unsigned int,而您的引用字段是 int

关于mysqli : Cannot create MANY to MANY table?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41752037/

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