mysql 自己与 2 个字段的关系

mysql self relationship with 2 field

我有 user table 这样的:

  id          email
-------------------------
  1       test@gmail.com

menu table这样:

  id   parent_id   user_id   name
-----------------------------------
  1       NULL        1      tets

我想自我关系 parent_id AND user_id.
如果黑客想添加此记录 mysql 忽略此操作,因为 user_id 2 不是所有者父菜单 1!! ! :

  id   parent_id   user_id   name
-----------------------------------
  2       1           2      tets

1.create table 用户 使用以下查询

create table User(id int primary key,email varchar(30));

2.create table 菜单 使用下面的查询

create table Menu(id,int,u_id int,p_id int,name varchar(10),primary key(u_id,p_id),
    constraint user_fk foreign key(id) references User(id) 
      on delete cascade);

当您输入 table 用户中不存在的值时,将抛出以下错误

Cannot add or update a child row: a foreign key constraint fails