Create foreign key using Phpmyadmin

By | May 9, 2020

The innodb storage engine supports foreign keys in Mysql.
To create foreign keys in phpmyadmin :

1. Convert both tables into innodb, if they are not already.

2. View the structure of the table which will have a foreign key. Make the referencing field an INDEX.

3. Now come back to structure view and click Relation view.

Phpmyadmin Relation View Link

Phpmyadmin Relation View Link

In the Relation view page the field (which was made an INDEX) can be made a foreign key referencing to some other field in another table.

Phpmyadmin Foreign Key

Phpmyadmin Foreign Key

That should do it.

About Silver Moon

A Tech Enthusiast, Blogger, Linux Fan and a Software Developer. Writes about Computer hardware, Linux and Open Source software and coding in Python, Php and Javascript. He can be reached at [email protected].

26 Comments

Create foreign key using Phpmyadmin
  1. Kieu Thi Anh

    Hi.
    Can you help me some problems.
    When I creat relationship between tables, It notice:Missing index on column. Why? And Must I do something to resolve them?
    Thanks so much.

  2. pash

    Hello…

    I have seen your post but in my phpmyadmin the option like relation view and track table does not available only rest of two available i am new user of mysql please help me..

    -Prashant

  3. slevon

    Hi,
    this is great!
    But I experienced that all my relations will be lost when I export and import the db.
    Do you know a way to keep this relations alive after a backup/restore process?

    Best wishes,
    slevon

    1. Binary Tides Post author

      If you use mysqldump then foreign keys are kept intact in the table definition.
      If you restore over existing tables (which dont have foreign key relation) then you need to drop tables so that fresh tables are created again with the correct foreign key relations.

Leave a Reply

Your email address will not be published. Required fields are marked *