我创建了两个表
DROP TABLE IF EXISTS `catalog_product_entity`;
CREATE TABLE `catalog_product_entity` (
  `entity_id` int(10) unsigned NOT NULL auto_increment,
  `entity_type_id` smallint(8) unsigned NOT NULL default '0',
  `attribute_set_id` smallint(5) unsigned NOT NULL default '0',
  `type_id` varchar(32) NOT NULL default 'simple',
  `sku` varchar(64) default NULL,
  `category_ids` text,
  `created_at` datetime NOT NULL default '0000-00-00 00:00:00',
  `updated_at` datetime NOT NULL default '0000-00-00 00:00:00',
  `has_options` smallint(1) NOT NULL default '0',
  PRIMARY KEY  (`entity_id`),
  KEY `FK_CATALOG_PRODUCT_ENTITY_ENTITY_TYPE` (`entity_type_id`),
  KEY `FK_CATALOG_PRODUCT_ENTITY_ATTRIBUTE_SET_ID` (`attribute_set_id`),
  KEY `sku` (`sku`),
  CONSTRAINT `FK_CATALOG_PRODUCT_ENTITY_ATTRIBUTE_SET_ID` FOREIGN KEY (`attribute_set_id`) REFERENCES `eav_attribute_set` (`attribute_set_id`) ON DELETE CASCADE ON UPDATE CASCADE,
  CONSTRAINT `FK_CATALOG_PRODUCT_ENTITY_ENTITY_TYPE` FOREIGN KEY (`entity_type_id`) REFERENCES `eav_entity_type` (`entity_type_id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=167 DEFAULT CHARSET=utf8 COMMENT='Product Entityies';DROP TABLE IF EXISTS `catalog_product_bundle_option`;
CREATE TABLE `catalog_product_bundle_option` (
  `option_id` int(10) unsigned NOT NULL auto_increment,
  `parent_id` int(10) unsigned NOT NULL,
  `required` tinyint(1) unsigned NOT NULL default '0',
  `position` int(10) unsigned NOT NULL default '0',
  `type` varchar(255) NOT NULL default '',
  PRIMARY KEY  (`option_id`),
  KEY `FK_CATALOG_PRODUCT_BUNDLE_OPTION_PARENT` (`parent_id`),
  CONSTRAINT `FK_CATALOG_PRODUCT_BUNDLE_OPTION_PARENT` FOREIGN KEY (`parent_id`) REFERENCES `catalog_product_entity` (`entity_id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=23 DEFAULT CHARSET=utf8 COMMENT='Bundle Options';当我往catalog_product_bundle_option插入数据时提示#1452 - Cannot add or update a child row: a foreign key constraint fails (`magento`.`catalog_product_bundle_option_value`, CONSTRAINT `FK_CATALOG_PRODUCT_BUNDLE_OPTION_VALUE_OPTION` FOREIGN KEY (`option_id`) REFERENCES `catalog_product_bundle_option` (`option_id`) O) ,无法插入数据
往catalog_product_entity插入数据时也是无法插入
删除两个表或级联关系时也无法删除,到底是什么原因呢,搞了一天了,头都大了

解决方案 »

  1.   

    看你上面的错误信息,说你的库里面另外有个表catalog_product_bundle_option_value外键于表catalog_product_bundle_option的字段option_id,你检查下相关表记录看看吧
      

  2.   

    不好意思,是我把错误信息贴错了
    应该是#1452 - Cannot add or update a child row: a foreign key constraint fails (`magento`.`catalog_product_bundle_option`, CONSTRAINT `FK_CATALOG_PRODUCT_BUNDLE_OPTION_PARENT` FOREIGN KEY (`parent_id`) REFERENCES `catalog_product_entity` (`entity_id`) ON DELETE CASCADE ON) 
      

  3.   

    测试如下。很显然你的insert 语句中的 parent_id 的值在catalog_product_entity 不存在。mysql> CREATE TABLE `catalog_product_entity` (
        -> `entity_id` int(10) unsigned NOT NULL auto_increment,
        -> `entity_type_id` smallint(8) unsigned NOT NULL default '0',
        -> `attribute_set_id` smallint(5) unsigned NOT NULL default '0',
        -> `type_id` varchar(32) NOT NULL default 'simple',
        -> `sku` varchar(64) default NULL,
        -> `category_ids` text,
        -> `created_at` datetime NOT NULL default '0000-00-00 00:00:00',
        -> `updated_at` datetime NOT NULL default '0000-00-00 00:00:00',
        -> `has_options` smallint(1) NOT NULL default '0',
        -> PRIMARY KEY  (`entity_id`),
        -> KEY `FK_CATALOG_PRODUCT_ENTITY_ENTITY_TYPE` (`entity_type_id`),
        -> KEY `FK_CATALOG_PRODUCT_ENTITY_ATTRIBUTE_SET_ID` (`attribute_set_id`),
        -> KEY `sku` (`sku`)
        -> ) ENGINE=InnoDB AUTO_INCREMENT=167 DEFAULT CHARSET=utf8 COMMENT='Product
    Entityies';
    Query OK, 0 rows affected (0.11 sec)mysql> CREATE TABLE `catalog_product_bundle_option` (
        -> `option_id` int(10) unsigned NOT NULL auto_increment,
        -> `parent_id` int(10) unsigned NOT NULL,
        -> `required` tinyint(1) unsigned NOT NULL default '0',
        -> `position` int(10) unsigned NOT NULL default '0',
        -> `type` varchar(255) NOT NULL default '',
        -> PRIMARY KEY  (`option_id`),
        -> KEY `FK_CATALOG_PRODUCT_BUNDLE_OPTION_PARENT` (`parent_id`),
        -> CONSTRAINT `FK_CATALOG_PRODUCT_BUNDLE_OPTION_PARENT` FOREIGN KEY (`parent
    _id`) REFERENCES `catalog_product_entity` (`entity_id`) ON DELETE CASCADE ON UPD
    ATE CASCADE
        -> ) ENGINE=InnoDB AUTO_INCREMENT=23 DEFAULT CHARSET=utf8 COMMENT='Bundle Op
    tions';
    Query OK, 0 rows affected (0.11 sec)mysql> insert into catalog_product_entity(category_ids) values ('test');
    Query OK, 1 row affected (0.33 sec)mysql> select * from catalog_product_entity;
    +-----------+----------------+------------------+---------+------+--------------+---------------------+---------------------+-------------+
    | entity_id | entity_type_id | attribute_set_id | type_id | sku  | category_ids | created_at          | updated_at          | has_options |
    +-----------+----------------+------------------+---------+------+--------------+---------------------+---------------------+-------------+
    |       167 |              0 |                0 | simple  | NULL | test         | 0000-00-00 00:00:00 | 0000-00-00 00:00:00 |           0 |
    +-----------+----------------+------------------+---------+------+--------------+---------------------+---------------------+-------------+
    1 row in set (0.00 sec)mysql> insert into catalog_product_bundle_option(parent_id) values (167);
    Query OK, 1 row affected (0.06 sec)mysql> select * from catalog_product_bundle_option;
    +-----------+-----------+----------+----------+------+
    | option_id | parent_id | required | position | type |
    +-----------+-----------+----------+----------+------+
    |        23 |       167 |        0 |        0 |      |
    +-----------+-----------+----------+----------+------+
    1 row in set (0.00 sec)mysql> insert into catalog_product_bundle_option(parent_id) values (999);
    ERROR 1452 (23000): Cannot add or update a child row: a foreign key constraint f
    ails (`csdn`.`catalog_product_bundle_option`, CONSTRAINT `FK_CATALOG_PRODUCT_BUN
    DLE_OPTION_PARENT` FOREIGN KEY (`parent_id`) REFERENCES `catalog_product_entity`
     (`entity_id`) ON DELETE CASCADE ON UP)
    mysql>
      

  4.   

    用户结帖率0.00%当您的问题得到解答后请及时结贴.
    http://topic.csdn.net/u/20090501/15/7548d251-aec2-4975-a9bf-ca09a5551ba5.html