0

Hey, I was wondering how do I add foreign keys in php MyAdmin? I tried changing the storage type to innoDB, but the option is not available to me ? any ideas ?

3
Contributors
4
Replies
32
Views
4 Years
Discussion Span
Last Post by IIM
0

phpMyAdmin lets you define foreign keys using their "relations" view. But since, MySQL only supports foreign constraints on "INNO DB" tables, the first step is to make sure the tables you are using are of that type.

To setup a foreign key so that the PID column in a table named CHILD references the ID column in a table named PARENT, you can do the following:

  • For both tables, go to the operations tab and change their type to "INNO DB"
  • Make sure ID is the primary key (or at least an indexed column) of the PARENT table.
  • In the CHILD table, define an index for the PID column.
  • While viewing the structure tab of the CHILD table, click the "relation view" link just above the "add fields" section.
  • You will be given a table where each row corresponds to an indexed column in your CLIENT table. The first dropdown in each row lets you choose which TABLE->COLUMN the indexed column references. In the row for PID, choose PARENT->ID from the dropdown and click GO.
    By doing an export on the CHILD table, you should see a foreign key constraint has been created for the PID column.

Take video of this:-
http://www.youtube.com/watch?v=IdQGFZwP7Xc

Edit:- You have option "operation" in your tab in php admin??
If yes then there you can see table opyions.There you can see storage engine???Change it to "InnoDB"
http://forums.cpanel.net/f5/innodb-not-enabled-default-87529-p2.html

Edited by IIM

0

I tried changing the storage type to innoDB, but the option is not available to me

I've come across web-hosts that have this feature disabled.

0

Yea i saw this somewhere already but I cant chande my database to InnoDB? theres is only four options. CSV,MRG_MYISAM,memory and MYISAM...

2

take a look at this.
On running
mysql> SHOW ENGINEs \g you can see what storage engines are there and what it supports.You can clearly see except innoDB no one supports foreign key.
6611c66c25b14da648a943a4a4786684

Edited by IIM

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.