这是我的数据库:
我试图在将数据插入到其周围的所有表中之后将数据插入到我的主链接表过程中。我已经检查了插入的数据,看起来没问题,我也检查了我的关系。
$proceduredata = array
(
'patient_id' => $patientfk,
'name_id' => $procedurenamefk,
'department_id' => $departmentfk,
'dosage_id' => $dosagefk,
'edocument' => NULL, //not implemented yet
'user_id' => $this->session->userdata('userID'),
'duration' => NULL, //not implemented yet
'submitted' => date('d-m-Y H:i:s', now()),
'comment' => NULL, //to be implemented
);
$insertprocedure = $this->db->insert('procedure', $proceduredata); //inserts into 'procedure' table with $proceduredata array
$procedurefk = $this->db->insert_id(); //gets the primary key of the row inserted
错误消息:
发生数据库错误
错误号码:1452
无法添加或更新子行:外键约束失败(
midas1
。procedure
,CONSTRAINTbelongs to a
FOREIGN KEY(department_id
)参考department
(department_id
))INSERT INTO
procedure
(patient_id
,name_id
,department_id
,dosage_id
,edocument
,user_id
,{{1 {},duration
,submitted
)VALUES(17,7,0,NULL,NULL,'2',NULL,'06 -07-2011 13:41:01',NULL)文件名:C:\ xampp \ htdocs \ midas \ system \ database \ DB_driver.php
行号:330
感谢您的时间
答案 0 :(得分:0)
$departmentfk
似乎是0
,但根据您在MySQL中的约束,需要是department
表中的ID。 MySQL检查department
表并找不到相应的ID,这就是它失败的原因。