MySQL - Error 1542

 
Vista:

Error 1542

Publicado por Erick (1 intervención) el 12/11/2022 23:46:46
Estoy intentando ejecutar este código:


Create database PERSONAL;
use Personal;
create table EMPLEADOS(
Clave_empleado varchar(8) primary key,
Nombre Varchar(30),
Apellidos Varchar(30),
Clave_Depto Int,
CONSTRAINT FK_Clave_Depto FOREIGN KEY (Clave_Depto)
REFERENCES Departamento(Clave_Depto)
);



create table DEPARTAMENTO(
Clave_Depto int primary key,
Nombre varchar(30),
Presupuesto int
);



insert into Empleados values
("EMP01","Armando","López",2 ),
("EMP02", "Tatiana", "Vargas", 1 ),
("EMP03", "Laura","Iturria", 3 ),
("EMP04","Juan" ,"Pérez", 4 ),
("EMP05", "Iván ","López" ,4 ),
("EMP06", "Margarita" ,"Hernández" ,1 ),
("EMP07", "Jesús" ,"Pérez" ,3 ),
("EMP08" ,"Tonatiuh" ,"Flores" ,2 ),
("EMP09" ,"Juan" ,"López" ,4 ),
("EMP10" ,"José", "Hernández" ,5 );




Al momento de crear las tablas todo aparece perfecto. Pero cuando quiero ingresar los datos me aparece este error

Error Code: 1452. Cannot add or update a child row: a foreign key constraint fails (`personal`.`empleados`, CONSTRAINT `FK_Clave_Depto` FOREIGN KEY (`Clave_Depto`) REFERENCES `departamento` (`Clave_Depto`))

No se que hacer. Ayuda :(
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder