Im trying to set up a foreign key within one of my tables although I don't get the option to select foreign key constraints as shown in the below screenshot. Any idea on how I can go about setting foreign keys?
Asked
Active
Viewed 179 times
0
-
Just to be sure: Are you using an engine that supports foreign keys? InnoDB does, most others don't. – Wander Nauta Mar 29 '15 at 00:59
-
Have you tried the steps in this answer? http://stackoverflow.com/q/459312/182402 – Wander Nauta Mar 29 '15 at 01:13
2 Answers
0
make sure you have both column type the same. without that, it will not show on your dropdown / unable to save

rezashamdani
- 577
- 6
- 11
-
Yes they are both the same type, i have tried to put this into the SQL although continues to give syntax errors: FOREIGN KEY (user_id) REFERENCES users(user_id) ON DELETE CASCADE – Peter Connolly Mar 29 '15 at 09:41
0
simply go to sql and go with the following query
ALTER TABLE `table_name_with_foreignKey`
ADD CONSTRAINT `foreignKey_constraint_name`
FOREIGN KEY (`Column_name_of_foreignkey`)
REFERENCES `table_having_referenceTokey`(`column_name_of_primaryKey`)
ON DELETE CASCADE
ON UPDATE CASCADE;

N.R
- 191
- 1
- 13