Reputation: 7053
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
) REFERENCESaws_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
) REFERENCEStasks
(task_id
) ON DELETE CASCADE ON UPDATE CASCADE)
Upvotes: 1
Views: 13034
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
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
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