n_n 관계가있는 crud에서 데이터 (또는 업데이트)를 저장하려고 할 때 문제가 있습니다. product_detail과 관련된 제품 테이블이 있습니다. 제품 세부 사항에 3 개의 외래 키가 있습니다. color라는 테이블과 다른 호출 된 자료에 연결하십시오. 어떤 생각이 왜 실패합니까?, 당신의 도움에 감사드립니다, 고마워요.식료품 점 Crude - CodeIgniter relation_n_n error
오류는 이것이다 :
데이터베이스 오류 발생
오류 번호 : 1452
추가 또는 자식 행을 업데이트 할 수 없습니다. 외래 키 제약 조건이 실패 (medina_db
을 product_detail
, CONSTRAINT product_detail_ibfk_3
외래 키 (material_id
) | 피드백 관련 용어 : material
(id
))
product_detail
(
product_id
,
color_id
) VALUES ('4', '1')
파일 이름 INTO
INSERT : /Applications/MAMP/htdocs/industrias_medina/models/grocery_crud_model.php
줄 번호 : 413
내 식료품 침전물 코드 :
$crud = new grocery_CRUD();
$crud->set_table('product')->set_subject('Productos');
$crud->set_relation_n_n("Colores", 'product_detail', 'color', 'product_id', 'color_id', 'name');
$crud->set_relation_n_n("Materiales", 'product_detail', 'material', 'product_id', 'material_id', 'name');
$crud->set_field_upload('image','assets/uploads/files');
$crud->fields('name','model','description', "Colores", "Materiales", 'image');
$output = $crud->render();
$this->_productos_output($output);
SQL은 : 당신의 product_detail 테이블 재료 테이블을 참조하는 material_id 열이 같은
CREATE TABLE `color` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(250) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=ucs2 AUTO_INCREMENT=2 ;
CREATE TABLE `material` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(250) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=2 ;
CREATE TABLE `product` (
`id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'Unique identifier',
`name` varchar(250) NOT NULL COMMENT 'Product''s name',
`model` varchar(250) NOT NULL COMMENT 'Product''s model',
`description` varchar(400) NOT NULL COMMENT 'Product''s description',
`image` varchar(400) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Table to store products' AUTO_INCREMENT=13 ;
CREATE TABLE `product_detail` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`product_id` int(11) NOT NULL,
`color_id` int(11) NOT NULL,
`material_id` int(11) NOT NULL,
PRIMARY KEY (`id`,`product_id`,`color_id`,`material_id`),
KEY `product_id` (`product_id`),
KEY `color_id` (`color_id`),
KEY `material_id` (`material_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=14 ;