삽입 내가 가진 5 개 테이블 MySql 제약 조건 위반.
students PK : ID -> anum, first, last
studentinfo PK/FK : ID -> why, student_commenets, finished, aidyear
Times PK/FK : ID -> signintime, counselor_start_time,
additional_time, finish_time
counselor PK/FK : ID -> firstcounselor, secondcounselor, thirdcounselor
Comments PK/FK : ID -> counselorcomments, additional_commenets
나는 세 가지 다른 테이블 (학생, studentinfo, 시간)
에 작성해야 해당 페이지의
signinpage.php라는 페이지가와 데이터베이스
내 코드 휴한지과 같습니다
if (empty($errors) === true)
{
include('core/queries/inserts.updates.selects/students.php');
include('core/queries/inserts.updates.selects/studentinfo.php');
include('core/queries/inserts.updates.selects/signintime.php');
$dbh = null;
header('location: signedin.php');
exit();
}
각 파일
실제 삽입 쿼리입니다. 나는 데 오류가을 (당신의 yall이 그들을 볼 필요가 있다면이 게시물을 업데이트합니다) :
(SQLSTATE [23000] : 무결성 제약 조건 위반 : 1452 추가하거나 할 수 없습니다 갱신 자식 행 : 외래 키 제약 조건이 실패
test
.
times
, CONSTRAINT
times_ibfk_2
FOREIGN KEY (
id
)는 UPDATE CASCADE ON DELETE CASCADE ON (
id
students
를) 참고 문헌)
이것에 추가하려면 첫 번째 쿼리 (students.php와 두 번째 쿼리 studentinfo.php) 이 제대로 삽입됩니다. 동일한 ID, 문제는 signintime을 table : times에 삽입 할 때 발생합니다.
phpmyadmin에서 학생 (또는 학생)이 세션 (PK ID)을 시작하기 때문에 두 테이블 (학생 정보와 시간)이 모두 삭제되어 캐스케이드되고 원래 테이블 (학생)로 업데이트되도록 구성됩니다.
어떻게이 오류를 해결할 수 있습니까?
편집 :
<?php
require('core/init.php');
try
{
$null = NULL;
$query = $dbh->prepare("INSERT INTO `times` (signintime) VALUES (:signintime)");
$query->bindParam(':signintime' , $null);
$query->execute();
}
catch (PDOException $e)
{
error_log($e->getMessage());
die($e->getMessage());
}
?>
안녕하세요,이 귀하의 질문에 관련이없는,하지만 당신은이 글을 읽고 혜택을 누릴 수 있습니다 : http://support.microsoft.com/kb/283878 – user1909426
그 주셔서 감사합니다. 이 비즈니스의 필요에 따라 중복 된 데이터 (anum = 학생 ID)를 저장해야합니다. 여러 명의 학생이 여러 번 들어 오기 때문입니다. 그때 나는 이것이 좋은 형태라고 느낀다. 그러나 독서 재료에 대한 tyvm! – RaGe10940