插入codeigniter时出错

时间:2011-10-08 12:55:05

标签: php mysql database codeigniter

我在插入表格时收到此错误:

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

有任何解决方案吗?

1 个答案:

答案 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;

在这里阅读

http://dev.mysql.com/doc/refman/5.5/en/innodb-foreign-key-constraints.html

 ALTER TABLE tbl_name DROP FOREIGN KEY fk_symbol