How do I add a foreign key in phpMyAdmin

 In phpmyadmin, i tried multiple times to add the foreign key using the tab "SQL" and type the query for foreign key like this.


ALTER TABLE contact  ADD CONSTRAINT fk_person FOREIGN KEY (Customer_Id)  

  REFERENCES customer(ID)  

  ON DELETE CASCADE

  ON UPDATE CASCADE


and this is not worked for me.


Now after searching on various pages, i found that the solution is - 

You can go to tab "Structure" at your table you want to create foreign key. Below tabs, you can see button named "Relation View". Click it and you see a page as image below. At "Foreign key constraints" section, you fill the form with correct info and click "Save" button to execute query.








Comments