I am facing problem an error in mysql integrity constraint violation:
tbl_project_user_assignment
CREATE TABLE tbl_project_user_assignment
(
project_id
int(11) NOT NULL,
user_id
int( NOT NULL,
role
varchar(64) DEFAULT NULL,
PRIMARY KEY (project_id
,user_id
),
KEY fk_project_user_role
(role
),
KEY fk_user_project
(user_id
),
CONSTRAINT fk_project_user
FOREIGN KEY (project_id
) REFERENCES tbl_project
(id
) ON DELETE CASCADE,
CONSTRAINT fk_project_user_role
FOREIGN KEY (role
) REFERENCES tbl_auth_item
(name
) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT fk_user_project
FOREIGN KEY (user_id
) REFERENCES tbl_user
(id
) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8
tbl_user
CREATE TABLE tbl_user
(
id
int(11) NOT NULL AUTO_INCREMENT,
username
varchar(255) NOT NULL,
email
varchar(255) NOT NULL,
password
varchar(255) NOT NULL,
last_login_time
datetime DEFAULT NULL,
create_time
datetime DEFAULT NULL,
create_user_id
int(11) DEFAULT NULL,
update_time
datetime DEFAULT NULL,
update_user_id
int(11) DEFAULT NULL,
PRIMARY KEY (id
)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8
The error I am facing is:
SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (trackstar
.tbl_project_user_assignment
, CONSTRAINT fk_project_user_role
FOREIGN KEY (role
) REFERENCES tbl_auth_item
(name
) ON DELETE CASCADE ON UPDATE CASCADE). The SQL statement executed was: INSERT INTO tbl_project_user_assignment
(role
, user_id
, project_id
) VALUES (:role, :user_id, :project_id)