当我需要在PHPMyAdmin中将字段设置为表中的外键时 . 我没有把它弄好 .
有一个名为'user'的父表,它有一个名为'uid'的主键 . 我使用名为'student_register'的子表中的'uid'作为外键 . 但是通过phpmyadmin中的关系视图链接将其设置为外键约束 . 我无法在下拉列表中看到'user'表来选择它并将'uid'设置为外键..我已经发送了屏幕截图以获得清晰的图像 . the screenshot for the phpmyadmin child table 'student_register'
2 回答
您应该将 index 添加到表用户的列uid中,以便显示在下拉列表中
获取表 user 的结构,然后单击Action的最后一个选项 - Add index 作为列uid .
From the MYSQL User Guide:
如果您遇到此问题,则需要遵循以下基本步骤:
数据库存储引擎必须是
InnoDB
.您的关系表必须是
InnoDB
.使用
UNIQUE
引用键 .参考键不能是
NULL
.两列的
Datatype
必须相同 .References:
Create Table Foreign Keys in MYSQL
Creating Foreign Key Relationships