mysql - 请问数据库表中可以在一个表里面有两个关联同一个表的外键吗
伊谢尔伦
伊谢尔伦 2017-04-17 11:57:33
0
1
646

具体是这样的:
我有一个用户表user,一个好友表fans。
fans中有三个字段 id,user_id,fans_id,其中user_id和fans_id都是跟user表的id关联的外键,我发现这样会报错。
可是用户跟好友的信息又要与用户表的信息关联,请问各位大神,怎样才不会报错或者有什么好一点的解决办法吗?

伊谢尔伦
伊谢尔伦

小伙看你根骨奇佳,潜力无限,来学PHP伐。

reply all(1)
小葫芦

See what error you reported.
Under normal circumstances, there will be no problem if two fields in one table are foreign key related to the same field in another table at the same time.
Unless the user_id in your fans table, the data type or size of the fans_id field does not match the id field of the user table; or the foreign key names are the same...

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template