我在插入表格时收到此错误:
A Database Error Occurred
Error Number: 1452
Cannot add or update a child row: a foreign key constraint fails (`giftme`.`giftme_shop`, CONSTRAINT `shop_ibfk_2` FOREIGN KEY (`sh_cid`) REFERENCES `giftme_shop_category` (`sc_cid`) ON DELETE CASCADE)
INSERT INTO `giftme_shop` (`sh_uid`, `sh_shop_name`, `sh_cid`) VALUES ('79', 'Naveen Reddys shop', 1)
Filename: /var/www/apps/helpers/sessions_helper.php
Line Number: 55
有任何解决方案吗?
答案 0 :(得分:3)
有外键引用
parent : `giftme_shop_category`.`sc_cid`
child : `giftme_shop`.sh_cid
父表中没有sc_cid=1
的值
删除外键约束
ALTER TABLE giftme_shop DROP FOREIGN KEY shop_ibfk_2;
在这里阅读
ALTER TABLE tbl_name DROP FOREIGN KEY fk_symbol