我有數據庫與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
我有一個名爲signinpage.php
該網頁我有寫信給三個不同的表(學生,studentinfo和時間)
上頁我的代碼休耕:
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();
}
每個文件的
是實際插入查詢。 (如果你亞勒需要看到他們,我會更新這個帖子)
我遇到的錯誤是:
SQLSTATE [23000]:完整性約束違規:1452不能添加或 更新子行:一個外鍵約束失敗(
test
。times
, 約束times_ibfk_2
外鍵(id
)參考文獻students
(id
)ON DELETE CASCADE ON UPDATE CASCADE)
要添加到此,第一個查詢(students.php和第二個查詢studentinfo.php) 插入就好了。相同的ID,登錄時間插入到表中會出現問題:時間。
在phpmyadmin中,兩個表(studentinfo和times)都配置爲相同,都有從學生開始會話(這是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 = student id),因爲多名學生多次進來。除此之外,我覺得這是一個很好的形式。然而tyvm的閱讀材料! – RaGe10940