私はデータベースプロジェクトを作成しています。 nullの外部キーを含む行を更新しようとすると、エラー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
が返されます。 nullの外部キーが含まれている行を追加できますが、更新はできません。(SQL)NULL外来キーエラーが含まれている行を更新します。
これは私の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
データベースの設計:
私はそれを理解していない、私はnullの列を挿入することはできますが、それを更新することはできません。
'location'テーブルがプライマリテーブルです。正しい?もしそうであれば、あなたが更新している間、ロケーションテーブル 'location_id'とアーティファクト' location_id'は同じタイプでなければなりません。 –
@elumalai_kpロケーションテーブルには主キーとしてlocation_idがあり、アーティファクトテーブルにはロケーションテーブルで参照される外部キーとしてlocation_idもあります。 location_ids '型はint [11]です。 –
ロケーションとアーティファクトテーブルのテーブル構造を表示できますか? –