我正在处理数据库项目。当我尝试更新包含空外键的行时,它会给我Cannot add or update a child row: a foreign key constraint fails ("archaelogy"."artifact", CONSTRAINT "location" FOREIGN KEY ("location_id") REFERENCES "location" ("location_id") ON DELETE NO ACTION ON UPDATE SET NULL
错误。我可以添加一个包含空外键但不能更新的行。(SQL)更新包含的空行外键错误
这是我的PHP代码:
function editArtifact($editData){
$query = "UPDATE artifact SET worker_id=?, image=?, period=?,location_id=?, coordinate_x=?, coordinate_y=?, type=?, comment=?) WHERE artifact_id=?";
$stmt = $this->con->prepare($query);
$stmt->bind_param("ibsiddsss", $editData['worker_id'],$editData['image'],$editData['period'],$editData['location_id'],$editData['coordinate_x'],$editData['coordinate_y'],$editData['type'],$editData['comment'],$editData['artifact_id']);
if ($stmt->execute()) {
echo json_encode(array("editStatus"=>array('success'=>true)));
}else{
echo json_encode(array("editStatus"=>array('success'=>false)));
}
$stmt->close();
}
,这是我的帖子:
artifact_id=qw & worker_id=1 & image=null & period=null & location_id=null & coordinate_x=null & coordinate_y=null & type=null & comment=null
数据库设计:
我不明白,我可以插入一个空列,但无法更新它。
'location'表是您的主表。正确?如果在更新时,位置表'location_id'和工件'location_id'应该是相同的类型。 –
@elumalai_kp位置表的location_id作为主键,工件表的location_id也与位置表引用的外键一样。 location_ids的类型是int [11]。 –
您可以显示位置和工件表的表格结构吗? –