Good hope you are very well, I come to you for help, you will see, I have several tables in my BD but the ones I think give me problems are the tables called "project" and "winner" , the "winner" table must have the primary key of "project" as a foreign key, and in fact it has it, but moment of wanting to insert records within my table called "triunfador" I can not since I get an error that does not let me continue, I hope you can help me understand this message and explain how to solve it, I inquired in San Google but I did not find an accurate answer, here is the error:
Uncaught PDOException: SQLSTATE[23503]: Foreign key violation: 7 ERROR: insert or update on table "triunfador" violates foreign key constraint "triunfador_id_pro_fkey" DETAIL: Key (id_pro)=(6) is not present in table "proyecto". in /var/www/html/Modulos/Fermary/modelo/anadir-triunfador-modelo.php:151 Stack trace: #0 /var/www/html/Modulos/Fermary/modelo/anadir-triunfador-modelo.php(151): PDOStatement->execute() #1 /var/www/html/Modulos/Fermary/modelo/anadir-triunfador-modelo.php(131): IncluirTriunfador->IncluirTriunfador() #2 /var/www/html/Modulos/Fermary/controlador/anadir-triunfador-controlador.php(37): IncluirTriunfador->IncluirT() #3 {main} thrown in /var/www/html/Modulos/Fermary/modelo/anadir-triunfador-modelo.php on line 151
This way my "triumphant" table was created, I will place it as it appears in the pgadmin3:
-- Table: public.triunfador
-- DROP TABLE public.triunfador;
CREATE TABLE public.triunfador
(
id_triun integer NOT NULL DEFAULT nextval('triunfador_id_triun_seq'::regclass),
nombre_triun character varying(50) NOT NULL,
apellido_triun character varying(50) NOT NULL,
cedula_triun integer NOT NULL,
trayecto_triun integer NOT NULL,
seccion_triun character varying(6) NOT NULL,
condicion_triun character varying(10) NOT NULL,
id_pro integer NOT NULL DEFAULT nextval('triunfador_id_pro_seq'::regclass),
CONSTRAINT triunfador_pkey PRIMARY KEY (id_triun),
CONSTRAINT triunfador_id_pro_fkey FOREIGN KEY (id_pro)
REFERENCES public.proyecto (id_pro) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION,
CONSTRAINT triunfador_cedula_triun_key UNIQUE (cedula_triun)
)
WITH (
OIDS=FALSE
);
ALTER TABLE public.triunfador
OWNER TO framework;
GRANT ALL ON TABLE public.triunfador TO framework;
GRANT ALL ON TABLE public.triunfador TO public;
And here is my other table called "project"
-- Table: public.proyecto
-- DROP TABLE public.proyecto;
CREATE TABLE public.proyecto
(
id_pro integer NOT NULL DEFAULT nextval('proyecto_id_pro_seq'::regclass),
nombre_pro character varying(50) NOT NULL,
trayecto_pro integer NOT NULL,
anio_pro integer NOT NULL,
id_asesor integer NOT NULL DEFAULT nextval('proyecto_id_asesor_seq'::regclass),
id_ald integer NOT NULL DEFAULT nextval('proyecto_id_ald_seq'::regclass),
CONSTRAINT proyecto_pkey PRIMARY KEY (id_pro),
CONSTRAINT fkald FOREIGN KEY (id_ald)
REFERENCES public.aldea (id_ald) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION,
CONSTRAINT fkasesor FOREIGN KEY (id_asesor)
REFERENCES public.asesor (id_asesor) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION
)
WITH (
OIDS=FALSE
);
ALTER TABLE public.proyecto
OWNER TO framework;
GRANT ALL ON TABLE public.proyecto TO framework;
GRANT ALL ON TABLE public.proyecto TO public;
-- Index: public.fki_fkald
-- DROP INDEX public.fki_fkald;
CREATE INDEX fki_fkald
ON public.proyecto
USING btree
(id_ald);
-- Index: public.fki_fkasesor
-- DROP INDEX public.fki_fkasesor;
CREATE INDEX fki_fkasesor
ON public.proyecto
USING btree
(id_asesor);
If it is not too much trouble if you can find the solution, it would be very helpful for me to explain in detail how to solve this so that in the future, if I am presented with this situation again, I can easily get out of it. thanks in advance my people.