php 在 phpmyadmin mysql 中创建外键

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18610038/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 17:54:51  来源:igfitidea点击:

Creating foreign key in phpmyadmin mysql

phpmysqldatabasemysqliphpmyadmin

提问by Hashim Adel

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

创建一个评论系统,每个评论都有一个简单的评分系统。

tables : 1.For the comments and it is called commentsand it has three columns : id, name, comment2. 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

表:1,为的意见,它被称为comments它有三列:idnamecomment2,对于没有评级的用户的IP,它被称为voted_ip,它有三列idcomment_iduser_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.

voted_ip 表的目的是我需要保存每个速率的 IP 地址以验证它如果存在则不能再次进行速率。

I created a foreign key from the child table voted_ipin the column comment_idconnecting it to the parent table commentsin the column idfollowing the steps at this linkand this videoon how to create a working foreign key except that the child table still do not update after a comment or a rate is inserted.

我按照此链接和此视频中的步骤从连接到voted_ipcomment_id中父表comments的列中的子表创建了一个外键,该视频介绍了如何创建工作外键,但子表在评论后仍不更新或插入汇率。id

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?

我想可能还有一步,或者我必须在项目的php方面做一些事情。我错过了什么?

回答by chowmean

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.

数据不会插入到另一个表“voted_ip”中,单独插入“评论”中,您必须明确添加它,此约束仅用于检查而不是自动在其他表中添加数据。