This is how I have the code MySQL
of my tables.
tasks :
CREATE TABLE tasks(
task_id INTEGER UNSIGNED PRIMARY KEY AUTO_INCREMENT,
created_by INTEGER UNSIGNED NOT NULL,
support_by INTEGER UNSIGNED,
customer_id INTEGER UNSIGNED NOT NULL,
request_of VARCHAR(45) NOT NULL,
description TEXT NOT NULL,
status_task ENUM('PENDIENTE', 'EN PROCESO', 'COMPLETADA', 'CANCELADA') NOT NULL,
start_date DATETIME NOT NULL,
finish_date DATETIME,
FOREIGN KEY (created_by) REFERENCES technicians(technician_id)
ON DELETE RESTRICT ON UPDATE CASCADE,
FOREIGN KEY (support_by) REFERENCES technicians(technician_id)
ON DELETE RESTRICT ON UPDATE CASCADE,
FOREIGN KEY (customer_id) REFERENCES customers(customer_id)
ON DELETE RESTRICT ON UPDATE CASCADE
);
technicians:
CREATE TABLE technicians(
technician_id INTEGER UNSIGNED PRIMARY KEY AUTO_INCREMENT,
name_tech VARCHAR(45) NOT NULL,
username_tech VARCHAR(15) UNIQUE NOT NULL,
pass_tech VARCHAR(255) NOT NULL,
role ENUM('technician', 'administrator') NOT NULL
);
It shows me the following error when wanting to insert data:
Fatal error: Uncaught PDOException: SQLSTATE [23000]: Integrity constraint violation: 1452 Can not add or update to child row: a foreign key constraint fails (
amber
.tasks
, CONSTRAINTtasks_ibfk_2
FOREIGN KEY (support_by
) REFERENCEStechnicians
(technician_id
) ON UPDATE CASCADE) in C: \ xampp \ htdocs \ amber \ db \ import.php: 107 Stack trace: # 0 C: \ xampp \ htdocs \ amber \ db \ import. php (107): PDOStatement-> execute () # 1 {main} thrown in C: \ xampp \ htdocs \ amber \ db \ import.php on line 107
Important:
What I want to do is to insert the support_by field as NULL but it does not allow it, I leave the code to insert it in the following link: import.php and the file tasks.json - Nilton Venegas 15 min ago