简体   繁体   English

我无法在PHPmyadmin XAMPP中设置外键

[英]I cannot set Foreign key in PHPmyadmin XAMPP

When i need to set a field as the foreign key in a table,in PHPMyAdmin. 当我需要将字段设置为表中的外键时,请使用PHPMyAdmin。 I am not getting it set right. 我没有把它设置正确。

There is a Parent table called 'user' which has a primary key called 'uid'.I am using the 'uid' in the child table called 'student_register' as foreign key. 有一个名为“ user”的父表,其主键为“ uid”。我在子表“ student_register”中使用“ uid”作为外键。 But while setting it as foreign key constraint through the relation view link in phpmyadmin . 但是,通过phpmyadmin中的关系视图链接将其设置为外键约束时。 i am not able to see the 'user' table in the drop down list to select it and set the 'uid' as foreign key .. I have sent the screen shot to get a clear picture. 我无法在下拉列表中看到“用户”表来选择它,并将“ uid”设置为外键..我已发送截屏以获得清晰的图片。 the screenshot for the phpmyadmin child table 'student_register' phpmyadmin子表“ student_register”的屏幕截图

You should add index to the column uid in table user in order to appear in the drop down list 您应该将索引添加到表用户中的列uid以便出现在下拉列表中

Take the structure of table user , then click the last option of the Action - Add index for the column uid. 采用表user的结构,然后单击“操作”“为列uid 添加索引 ”的最后一个选项。

From the MYSQL User Guide: 从《 MYSQL用户指南》中:

If you are facing this issue than you need to follow these basic steps: 如果您遇到此问题,则需要执行以下基本步骤:

  1. Database storage engine must be InnoDB . 数据库存储引擎必须是InnoDB
  2. Your relational tables must be InnoDB . 您的关系表必须是InnoDB
  3. Use UNIQUE reference key. 使用UNIQUE参考键。
  4. Reference Key can not be NULL . Reference Key不能为NULL
  5. Datatype of the both columns must be same. 两列的Datatype必须相同。

References: 参考文献:

Create Table Foreign Keys in MYSQL 在MYSQL中创建表外键

Creating Foreign Key Relationships 创建外键关系

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM