I have an existing InnoDB table which already has foreign keys pointing to different tables.
我有一个现有的InnoDB表,它已经有指向不同表的外键。
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.
该表是User with User_Id作为Primary。
I want a foreign key Manager_ID which is a FK to User_Id.
我想要一个外键Manager_ID,这是一个FK到User_Id。
Both of INT Both of Length 10 Unsigned...
两个INT都是长度10无符号...
But I still get a data check error...?
但我仍然得到数据检查错误......?
1 个解决方案
#1
14
Make sure that Manager_ID is not set to NOT NULL
.
确保Manager_ID未设置为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.
我在MySQL板上发现了一条可能有用的帖子。
#1
14
Make sure that Manager_ID is not set to NOT NULL
.
确保Manager_ID未设置为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.
我在MySQL板上发现了一条可能有用的帖子。