1

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)

Dmitry Makovetskiyd
  • 6,942
  • 32
  • 100
  • 160

3 Answers3

3

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?

Community
  • 1
  • 1
Faizan Ali
  • 509
  • 12
  • 35
2

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.

Robert
  • 5,278
  • 43
  • 65
  • 115
GarryOne
  • 1,430
  • 17
  • 21
0

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

neetu
  • 107
  • 2
  • 10