Reputation: 33
When i need to set a field as the foreign key in a table,in PHPMyAdmin. I am not getting it set right.
There is a Parent table called 'user' which has a primary key called 'uid'.I am using the 'uid' in the child table called 'student_register' as foreign key. But while setting it as foreign key constraint through the relation view link in phpmyadmin . i am not able to see the 'user' table in the drop down list to select it and set the 'uid' as foreign key .. I have sent the screen shot to get a clear picture. the screenshot for the phpmyadmin child table 'student_register'
Upvotes: 0
Views: 2422
Reputation: 1
If you are facing this issue than you need to follow these basic steps:
First login into the phpMyAdmin
Then open the database
Then open the table where you want to apply the Foreign Key
Then go to the Operation Tab
Then go to the Table Options
Then check the storage engine in the table options
If the storage engine type is MyISAM then you can not apply the Foregin Key in that database because the storage engine MyISAM does not support foreign key constraints
That why you need to change the Storage Engine Type: InnoDB from the MyISAM
Then click on Go Button for apply the Changes
Upvotes: 0
Reputation: 16117
From the MYSQL User Guide:
If you are facing this issue than you need to follow these basic steps:
InnoDB
.InnoDB
.UNIQUE
reference key.NULL
.Datatype
of the both columns must be same.References:
Create Table Foreign Keys in MYSQL
Creating Foreign Key Relationships
Upvotes: 1
Reputation: 4739
You should add index to the column uid in table user in order to appear in the drop down list
Take the structure of table user, then click the last option of the Action - Add index for the column uid.
Upvotes: 0