I am a beginner in mysql and can not add a fk to a table I created. I have two tables (person, object) and I want to create a 'fk_person' in an object that receives the value of the 'id' attribute of the person. The tables are already configured to use the InnoDB engine. I have typed the following:
ALTER TABLE objeto ADD CONSTRAINT fk_pessoa FOREIGN KEY(id) REFERENCES pessoa (id);
Then it returns this to me:
ERROR 1072 (42000): Key column 'id' does not exist in table
I tried to follow the pattern of this video: link "Creating Tables in MySQL 5 with Foreign Keys"
and also tried to follow the example of devmedia link
p>My object table looks like this:
id_objeto int(4) PRIMARY KEY auto_increment
fk_pessoa int(4) NOT NULL
My person table looks like this:
id int(4) PRIMARY KEY auto_increment
Thank you in advance