I am working on a database project. When i try to update row which is included null foreign key it gives me 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
error. I can add a row which is included null foreign key but can't update it.
This is my php code :
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();
}
and this is my post:
artifact_id=qw & worker_id=1 & image=null & period=null & location_id=null & coordinate_x=null & coordinate_y=null & type=null & comment=null
Database design:
I don't understand that, I can insert a null column but can't update it.