I have child table my_contacts and parent table profession. profession table is created with this code:
CREATE TABLE profession(
prof_id INT NOT NULL,
profession VARCHAR(20) NOT NULL
);
now I am trying to add a foreign key in my_contacts table by this command:
ALTER TABLE my_contacts
ADD COLUMN prof_id INT NOT NULL,
ADD CONSTRAINT profession_prof_id_fk
FOREIGN KEY (prof_id)
REFERENCES profession (prof_id);
I get this error: Error 1052 (23000): Cannot add or update a child row: a foreign key constraint fails.