Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating foreign key in phpmyadmin mysql

Creating a comment system with a simple rating system for each comment.

tables : 1.For the comments and it is called comments and it has three columns : id, name, comment 2. for the IP of the user that did the rating and it is called voted_ipand it has three columns id, comment_id, user_ip

The purpose of the voted_ip table is that i need to save the IP address for each rate to validate it that it cannot rate again if it exists.

I created a foreign key from the child table voted_ip in the column comment_id connecting it to the parent table comments in the column id following the steps at this link and this video on how to create a working foreign key except that the child table still do not update after a comment or a rate is inserted.

as follow : the foreign key creation

I thought about that there might be another step or I have to do something in the php side of the project. What am I missing?

like image 504
Hashim Adel Avatar asked Nov 02 '22 15:11

Hashim Adel


1 Answers

Data is not inserted in the other table "voted_ip" on insertion in "comment" by itself you have to add it explicitly this constraints are just for checking not for adding data in other table automatically.

like image 107
chowmean Avatar answered Nov 09 '22 06:11

chowmean