简体   繁体   English

在phpmyadmin中添加外键

[英]Add foreign key in phpmyadmin

Following images are my table structure and the relational view form in phpmyadmin下图是我的表结构和phpmyadmin中的关系视图表单

在此处输入图片说明

在此处输入图片说明

My question is how to add foreign key for 'org_id' column, 'org_id' is also an integer field and it's unsigned field but why it isn't allow to add a foreign key.我的问题是如何为“org_id”列添加外键,“org_id”也是一个整数字段,它是无符号字段,但为什么不允许添加外键。

MySQL forces you to index foreign key. MySQL强制您索引外键。

MySQL requires indexes on foreign keys and referenced keys so that foreign key checks can be fast and not require a table scan. MySQL 需要外键和引用键的索引,以便外键检查可以快速并且不需要表扫描。

You can read more about foreign keys on MySQL documentation pages: http://dev.mysql.com/doc/refman/5.7/en/create-table-foreign-keys.html您可以在 MySQL 文档页面上阅读有关外键的更多信息: http : //dev.mysql.com/doc/refman/5.7/en/create-table-foreign-keys.html

Just had to figure this out for myself:只需要自己解决这个问题:

  • Open the table you want to add foreign keys too.打开要添加外键的表。

  • Click the Structure Tab单击结构选项卡

  • Click the RELATION VIEW button just above the list of columns单击列列表正上方的 RELATION VIEW 按钮

  • Enter data for in the Foreign key constraints box在外键约束框中输入数据

  • DO NOT index the column you want to make into a Foreign Key first.不要首先将要制作成外键的列编入索引。 This caused my creation attempts to fail这导致我的创作尝试失败

父表中的 org_id 应该被索引,所以只需在父表中创建索引,然后创建外键。

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

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