我的网站的一部分有问题。您可以导入 excel 文件,该文件将创建产品并将它们链接到分类。当我导入我的 excel 时,有些行正在工作,而另一些行则没有。错误消息如下:
无法添加或更新子行:外键约束失败 (
shop
。produit_categorie
、约束FK_produit_categorie_categorie_id
外键(categorie_id
(引用categorie
(categorie_id
((
这是导入 excel 时的代码:
public static function saveData(PDO $bdd, PHPExcel_Worksheet $objWorksheet, $constructeur_id, $catalogue_id) {
/* . . . */
else if ($type == RowType::PRODUIT) {
$data_array = self::getRowData($row);
$taxe_id = self::generateTaxe($bdd);
$produit_id = self::generateProduit($bdd, $data_array, $constructeur_id, $taxe_id);
self::generatePrixProduitCatalogue($bdd, $data_array, $produit_id, $catalogue, $catalogue_id, $cpt_row_full);
self::generateCategorieProduit($bdd, $categorie_id_courante, $produit_id);
$code_retour = "200";
} else if ($type == RowType::PLATEFORME) {
// si la ligne est autre chose que produit ou info -> donc intitule plateforme
$code_retour = "200";
} else {
// erreur
$code_retour = "400_" . $cpt_row;
break;
}
}
$cpt_row_full++;
}// fin IF "ligne pas vide"
$cpt_row++;
}// fin foreach
echo $code_retour;
}
因此,产品是在我的数据库中自然创建的。但我不明白的是为什么有些产品工作正常而其他一些产品(在同一个 excel 上,相同的型号,但 2 行后,下一个可以工作(。
你有什么想法吗?
也许检查您是否在 excel 工作表中将任何值设置为 0 或空白,或者是否正在尝试在 excel 中分配不存在的 ID。