php - phpmyadmin doesnt allow me to add primary/foreign key relationship

225

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 TABLEurl_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)

126

Answer

Solution:

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?

584

Answer

Solution:

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.

799

Answer

Solution:

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

People are also looking for solutions to the problem: php - Can I include some javascript in a Facebook feed?

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.