简体   繁体   中英

Add foreign key in phpmyadmin

Following images are my table structure and the relational view form in 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.

MySQL forces you to index foreign key.

MySQL requires indexes on foreign keys and referenced keys so that foreign key checks can be fast and not require a table scan.

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

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

  • 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 应该被索引,所以只需在父表中创建索引,然后创建外键。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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