Yii Framework Forum: Error In Adding User To Project - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Error In Adding User To Project 1452 integrity constraint violation

#1 User is offline   saurabh570 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 1
  • Joined: 26-June 14

Posted 27 June 2014 - 03:35 AM

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(8) 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)

Attached File(s)


0

#2 User is offline   danial32 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 1
  • Joined: 09-September 14

Posted 16 September 2014 - 01:22 AM

While inserting auto increament field, you should not specify table itelf.

"INSERT INTO prod_categorie (categorieID, parentID) VALUES (?, ?)", array($chkParent, $txtParentCategorie));
^^^^^^^^^^^ ^ ^^^^^^^^^^
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users