how do I add a foreign key pointing to the same table using phpMyAdmin?

南楼画角 提交于 2019-12-09 16:55:21

问题


I have an existing InnoDB table which already has foreign keys pointing to different tables.

But when I try to create a foreign key pointing to the Primary index, I get an error (check data type).

The table is User with User_Id as the Primary.

I want a foreign key Manager_ID which is a FK to User_Id.

Both of INT Both of Length 10 Unsigned...

But I still get a data check error...?


回答1:


Make sure that Manager_ID is not set to NOT NULL.

You have to allow nulls on that field, as the top-most person in the company will have no manager.

I found a post over on the MySQL boards that might help.



来源:https://stackoverflow.com/questions/675037/how-do-i-add-a-foreign-key-pointing-to-the-same-table-using-phpmyadmin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!