Dmitry Makovetskiyd
Dmitry Makovetskiyd

Reputation: 7053

phpmyadmin doesnt allow me to add primary/foreign key relationship

That is the primary table field (tasks table):

task_id int(10)     UNSIGNED    No  None    AUTO_INCREMENT

This is my foreign table field (url_error_stats table):

task_id int(10)     UNSIGNED    No  None    

url_error_stats doesnt present the "relation view" option to connect between the keys..why?

SQL query:

ALTER TABLE url_error_stats ADD FOREIGN KEY ( task_id ) REFERENCES aws_backlinks.tasks (

task_id ) ON DELETE CASCADE ON UPDATE CASCADE ;

MySQL said:

1452 - Cannot add or update a child row: a foreign key constraint fails (aws_backlinks., CONSTRAINT #sql-6f0_3bd_ibfk_1 FOREIGN KEY (task_id) REFERENCES tasks (task_id) ON DELETE CASCADE ON UPDATE CASCADE)

Upvotes: 1

Views: 13034

Answers (3)

GarryOne
GarryOne

Reputation: 1488

Another reason can be the unrelated data in your tables. I mean you may have a foreign key that doesn't exist in parent table.

Upvotes: 2

neetu
neetu

Reputation: 107

in this , click on url_error_stats table, then on right hand side it will show all the fields list, so now check on checkbox of that particular field which u wanted to be foreign and click on the link relation view (which is provided by phpmyadmin below to the table fields with blue color hyperlink).

it will open relationship screen , there You can select the field of the primary table. Thanks

Upvotes: 0

Faizan Ali
Faizan Ali

Reputation: 509

you have to use innodb and index the primary key if you want to create the foreign keys. and I will recommend you to use NAVICAT . its much easier to create foreign keys and quick too. but for a quick phpmyadmin guide see

Setting up foreign keys in phpMyAdmin?

Upvotes: 3

Related Questions