Create foreign key using Phpmyadmin

24 Flares Filament.io 24 Flares ×

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.







Last Updated On : 25th August 2009

Subscribe to get updates delivered to your inbox

About Silver Moon

Php developer, blogger and Linux enthusiast. He can be reached at m00n.silv3r@gmail.com. Or find him on

  • Ashikuzzaman Ashik

    Thanks for helping us freely.

  • praveen

    yeah it works fine

  • shanu

    thank yewwwww

  • Med

    Thank you, It was interesting

  • Musa

    Thanks

  • dev31

    worth able info thank u

  • 2m935h

    Thanks Buddy it really works…

  • http://www.spbca.in 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

  • vinay

    Thanks man..! it worked..

  • 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

    • Binary Tides

      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.

  • Serikjan

    Thank you very much. So much help

  • http://rakesh.tembhurne.com Rakesh Tembhurne

    That’s what I was looking for. Now I can get associated models work together in CakePHP. Thanks!

  • Dhanya

    Thank You very much…..
    It ws really very useful….

  • http://www.kavita.amara.com venkat

    tnx dear

  • Thilini

    Thanks. Clear and to the point.

  • mano

    hi..i wanna know how to create foreign key within phpmyadmin
    can anyone plz help……

  • http://viral-stuff.blogspot.com Viral

    Thanks buddy

  • Gautam

    plz tell me how to create forign key in phpmyadmin through diagram………

  • xxx

    thanks for the info. Just exactly what I need. :)

24 Flares Twitter 0 Facebook 21 Google+ 3 LinkedIn 0 StumbleUpon 0 Pin It Share 0 Filament.io 24 Flares ×