Номер ошибки: 1452
Невозможно добавить или обновить дочернюю строку: ограничение внешнего ключа не выполняется (smp
. student
, CONSTRAINT FK_ParentStudent
FOREIGN KEY (p_id
) ССЫЛКИparent
(p_id
) НА УДАЛЕННОМ КАСКАДЕ НА ОБНОВЛЕНИИ КАСКАДА)
ВСТАВИТЬ В student
(s_id
, student_code
, f_name
, l_name
, dob
, gender
, address
, tel
, username
, password
) ЗНАЧЕНИЯ ('', 'cbg', 'sdfsdf', 'sdfsd', '02 / 13/2019 ',' male ',' fgfhnf ','', 'admin', 'pAQ7oL + r8QJNgy2siN5moyJUhrgSj5tq3Ai5U2ngMyvaQZDsS9ooPbfcCm8qKEWi1C6nbYdMCyscz6ngU + 1Tiw ==' * /691
Я получаю эту ошибку, и я думаю, что это как-то связано с моей функцией в контроллере
public function register_students() {
// $this->load->model('Register_model','multi_model',TRUE);
$encrypted_password1 = $this->encrypt->encode($this->input->post('p_pwd'));
$parent_data = array(
'p_id' => '',
'parent_code' => $this->input->post('parent_code'),
'f_name' => $this->input->post('p_first_name'),
'l_name' => $this->input->post('p_last_name'),
'dob' => $this->input->post('p_dob'),
'address' => $this->input->post('p_address'),
'tel' => $this->input->post('p_tel_no'),
'email' => $this->input->post('email'),
'username' => $this->input->post('p_username'),
'password' => $encrypted_password1,
);
// var_dump($student_data);
// var_dump($parent_data);
$result = $this->Model_Action->insertTable('parent', $parent_data);
$encrypted_password = $this->encrypt->encode($this->input->post('pwd'));
$student_data = array(
's_id' => '',
'student_code' => $this->input->post('student_code'),
'f_name' => $this->input->post('first_name'),
'l_name' => $this->input->post('last_name'),
'dob' => $this->input->post('dob'),
'gender' => $this->input->post('gender'),
'address' => $this->input->post('address'),
'tel' => $this->input->post('tel_no'),
'username' => $this->input->post('username'),
'password' => $encrypted_password,
);
$result = $this->Model_Action->insertTable('student', $student_data);
// $result = $this->multi_model->student_register($student_data, $parent_data);
if($result) {
redirect('student');
}
else
{
redirect('student');
}
}
модель
function insertTable($table, $data) {
$this->db->insert($table, $data);
return $this->db->insert_id();
}
CREATE TABLE student
(s_id
int (11) NOT NULL AUTO_INCREMENT, student_code
varchar (50) NOT NULL, f_name
varchar (150) NOT NULL, l_name
varchar (250) NOT NULL, DOB
текст NOT NULL), gender
enum ('male', 'female') NOT NULL, address
varchar (450) NOTNULL, tel
int (50) NOT NULL, username
varchar (100) NOT NULL, password
varchar (150) NOT NULL, p_id
int (11) NOT NULL, ПЕРВИЧНЫЙ КЛЮЧ (s_id
),KEY s_id
(s_id
), KEY p_id
(p_id
), CONSTRAINT FK_ParentStudent
FOREIGN KEY (p_id
) ССЫЛКИ parent
(p_id
) НА УДАЛИТЬ КАСКАД НА ОБНОВЛЕНИИ КАСКАДОВ) ENGINE = InnoDBAUTO_INCREMENT = 16 CHARSET ПО УМОЛЧАНИЮ = latin1
CREATE TABLE parent
(p_id
int (11) NOT NULL AUTO_INCREMENT, parent_code
varchar (100) NOT NULL, f_name
varchar (150) NOT NULL,l_name
varchar (250) NOT NULL, DOB
текст NOT NULL, address
varchar (250) NOT NULL, tel
varchar (50) NOT NULL, email
varchar (250) NOT NULL, username
varchar (250) NOT NULL, password
varchar (250) NOT NULL, первичный ключ (p_id
), ключ p_id
(p_id
)) ENGINE = InnoDB AUTO_INCREMENT = 10 CHARSET по умолчанию = латинский 1