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
Creating foreign key in phpmyadmin mysql
提问by Hashim Adel
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_ip
and it has three columns id
, comment_id
, user_ip
表:1,为的意见,它被称为comments
它有三列:id
,name
,comment
2,对于没有评级的用户的IP,它被称为voted_ip
,它有三列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.
voted_ip 表的目的是我需要保存每个速率的 IP 地址以验证它如果存在则不能再次进行速率。
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 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_ip
列comment_id
中父表comments
的列中的子表创建了一个外键,该视频介绍了如何创建工作外键,但子表在评论后仍不更新或插入汇率。id
as follow :
如下 :
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”中,单独插入“评论”中,您必须明确添加它,此约束仅用于检查而不是自动在其他表中添加数据。