Jump to content


Selectionbox - set_relation not working?

set_relation; mysql;

  • Please log in to reply
No replies to this topic

#1 jep

jep

    Newbie

  • Members
  • Pip
  • 6 posts
  • Locationargentina

Posted 29 April 2019 - 07:06 PM

hello all, in advance THANK YOU VERY MUCH for your help and sorry for my english ;-)
 
i'm working on a form that register building access.
After entry all data in form (view FUNCTION) and i click save button, it shows me error (view ERROR LOG).
 
i have several tables (2) where store data, (1) table that help fill table_1, same than other which i have no problems.-
 
problem is that crud form send the id number (INT) either name (VARCHAR)
 
selection box:
$crud->set_relation('mhwh_reponsable' ,'lst_responsables' ,'resp_nombre' );
 
as you can see i have several selection boxes and all of them are working fine.
 
MYSQL side
-data is equal = varchar (55)
-collate is equal = 'utf8mb4_0900_ai_ci'
-relation are set = 1 to n
-i have created new table and made new relations and index and im keeping this error.
 
 
VERSIONS
CodeIgniter v3.1.9
GroceryCrud v1.6.1
database: mysql - > 8.0.11

 

 
//-----------------------------------------------------------------------------------------------//
FUNCTION
//-----------------------------------------------------------------------------------------------//
$crud = new grocery_CRUD();
$this->load->config('grocery_crud');
$this->config->set_item('grocery_crud_file_upload_allow_file_types','gif|jpeg|jpg|png|pdf');
$crud->set_theme('datatables'); //  datatables o flexigriS
$crud->set_table('t_mhw_header'); //tab_movimiento_hw
$crud->set_subject('Movimiento HW');


$crud->where('mhwh_fk_etarea','En Progreso');


$crud->fields( 'mhwh_id_ticket', 'mhwh_fhrealizacion', 'mhwh_fk_edificio', 'mhwh_fk_sala',
'mhwh_reponsable', 'mhwh_fk_tdocumento', 'mhwh_ndocumento', 'mhwh_fk_cliente', 
'mhwh_observaciones', 'mhwh_firma', 'mhwh_fk_ssff', 'mhwh_fk_etarea');


$crud->columns(array('id_mhwh' ,'mhwh_fk_cliente', 'mhwh_reponsable' ,'mhwh_id_ticket',
'mhwh_fk_sala' ,'mhwh_fk_etarea',  'mhwh_observaciones'));


$crud->set_relation('mhwh_fk_tdocumento' ,'lst_tipo_documentos' ,'id_tdocumentos' );
$crud->set_relation('mhwh_fk_etarea' ,'lst_estado_tareas' ,'id_estado_tarea' );
$crud->set_relation('mhwh_reponsable' ,'lst_responsables' ,'resp_nombre' );
$crud->set_relation('mhwh_fk_ssff' ,'lst_operariosssff' ,'id_opersssff' );
$crud->set_relation('mhwh_fk_sala' ,'lst_salas' ,'id_salas' );
$crud->set_relation('mhwh_fk_edificio' ,'lst_edificios' ,'id_edificios' );
$crud->set_relation('mhwh_fk_cliente' ,'lst_clientes' ,'id_cliente' );


$crud->set_field_upload('mhwh_firma','assets/Firmas');


$crud->unset_clone();  // quitar boton de clonacion
$crud->unset_read();  // quitar boton de lectura, ingresando al tkt
$crud->unset_delete(); // quitar boton de elimiacion


$crud->add_action('HW' ,'','','ui-icon-clipboard' ,array($this,'fadd_add_hardware'));
$crud->add_action('Print' ,'','','ui-icon-print' ,array($this,'fadd_prt_movimiento_hw'));


$output = $crud->render();
$this->_load_outputHead($output);
 
//-----------------------------------------------------------------------------------------------//
ERROR LOG
//-----------------------------------------------------------------------------------------------//
ERROR - 2019-04-26 22:55:03 --> Query error: Cannot add or update a child row: 
a foreign key constraint fails (`idcdb`.`t_mhw_header`, CONSTRAINT `FK_t_mhw_header_lst_responsables` FOREIGN KEY (`mhwh_reponsable`) REFERENCES `lst_responsables` (`resp_nombre`)) 
- Invalid query: 
INSERT INTO `t_mhw_header` (`mhwh_id_ticket`, `mhwh_fhrealizacion`, `mhwh_fk_edificio`, `mhwh_fk_sala`, `mhwh_reponsable`, `mhwh_fk_tdocumento`, `mhwh_ndocumento`, `mhwh_fk_cliente`, `mhwh_observaciones`, `mhwh_firma`, `mhwh_fk_ssff`, `mhwh_fk_etarea`) 
VALUES ('Q00000000', NULL, 'EDIFICIO', 'UBICACION', '2789', 'TIPO-DOCUMENTO', '00000000', 'NOMBRE_CLIENTE', 'OBSERVACIONES', NULL, 'NOMBRE_SSFF', 'En Progreso')
 
'27789' MIGHT BE A NAME, NOT ID RECORD.
//-----------------------------------------------------------------------------------------------//
SQL
//-----------------------------------------------------------------------------------------------//
//---------------------------------------------------------//
TABLE_1
//---------------------------------------------------------//
CREATE TABLE `lst_responsables` (
`resp_nombre` VARCHAR(55) NULL DEFAULT NULL,
`resp_tdocumento` VARCHAR(55) NULL DEFAULT NULL,
`resp_ndocumento` VARCHAR(15) NULL DEFAULT NULL,
`resp_legajo` VARCHAR(15) NULL DEFAULT NULL,
`resp_empresa` VARCHAR(55) NULL DEFAULT NULL,
`resp_telefono` VARCHAR(22) NULL DEFAULT NULL,
`resp_interno` VARCHAR(11) NULL DEFAULT NULL,
`resp_email` VARCHAR(55) NULL DEFAULT NULL,
`resp_udf__Rol` VARCHAR(22) NULL DEFAULT NULL,
`resp_udf__Rol2` VARCHAR(22) NULL DEFAULT NULL,
`id_resp_autorizante` INT(11) NOT NULL AUTO_INCREMENT,
PRIMARY KEY (`id_resp_autorizante`),
INDEX `resp_nombre` (`resp_nombre`)
)
COLLATE='utf8mb4_0900_ai_ci'
ENGINE=InnoDB
AUTO_INCREMENT=2790
;
//---------------------------------------------------------//
TABLE_2
//---------------------------------------------------------//
CREATE TABLE `t_mhw_header` (
`id_mhwh` INT(11) UNSIGNED ZEROFILL NOT NULL AUTO_INCREMENT COMMENT 'ok',
`mhwh_id_ticket` VARCHAR(55) NULL DEFAULT NULL COMMENT 'ok',
`mhwh_fhrealizacion` DATETIME NULL DEFAULT NULL COMMENT 'ok',
`mhwh_fk_edificio` VARCHAR(55) NULL DEFAULT NULL COMMENT 'ok',
`mhwh_fk_sala` VARCHAR(55) NULL DEFAULT NULL COMMENT 'ok',
`mhwh_reponsable` VARCHAR(55) NULL DEFAULT NULL COMMENT 'ok',
`mhwh_fk_tdocumento` VARCHAR(55) NULL DEFAULT NULL COMMENT 'ok',
`mhwh_ndocumento` VARCHAR(11) NULL DEFAULT NULL COMMENT 'ok',
`mhwh_fk_cliente` VARCHAR(55) NULL DEFAULT NULL COMMENT 'ok',
`mhwh_observaciones` VARCHAR(255) NULL DEFAULT NULL COMMENT 'ok',
`mhwh_firma` VARCHAR(255) NULL DEFAULT NULL COMMENT 'ok',
`mhwh_fk_ssff` VARCHAR(55) NULL DEFAULT NULL COMMENT 'ok',
`mhwh_fk_etarea` VARCHAR(55) NULL DEFAULT NULL,
PRIMARY KEY (`id_mhwh`),
INDEX `id_movimientohw` (`mhwh_id_ticket`),
INDEX `FK_tab_mov_hw_header_lst_estado_tareas` (`mhwh_fk_etarea`),
INDEX `FK_tab_mov_hw_header_lst_operariosssff` (`mhwh_fk_ssff`),
INDEX `FK_tab_mov_hw_header_lst_salas` (`mhwh_fk_sala`),
INDEX `FK_tab_mov_hw_header_lst_tipo_documentos` (`mhwh_fk_tdocumento`),
INDEX `FK_t_mhw_header_lst_edificios` (`mhwh_fk_edificio`),
INDEX `FK_t_mhw_header_lst_clientes` (`mhwh_fk_cliente`),
INDEX `mhwh_reponsable` (`mhwh_reponsable`),
CONSTRAINT `FK_t_mhw_header_lst_clientes` FOREIGN KEY (`mhwh_fk_cliente`) REFERENCES `lst_clientes` (`id_cliente`),
CONSTRAINT `FK_t_mhw_header_lst_edificios` FOREIGN KEY (`mhwh_fk_edificio`) REFERENCES `lst_edificios` (`id_edificios`),
CONSTRAINT `FK_t_mhw_header_lst_responsables` FOREIGN KEY (`mhwh_reponsable`) REFERENCES `lst_responsables` (`resp_nombre`),
CONSTRAINT `FK_tab_mov_hw_header_lst_estado_tareas` FOREIGN KEY (`mhwh_fk_etarea`) REFERENCES `lst_estado_tareas` (`id_estado_tarea`),
CONSTRAINT `FK_tab_mov_hw_header_lst_operariosssff` FOREIGN KEY (`mhwh_fk_ssff`) REFERENCES `lst_operariosssff` (`id_opersssff`),
CONSTRAINT `FK_tab_mov_hw_header_lst_salas` FOREIGN KEY (`mhwh_fk_sala`) REFERENCES `lst_salas` (`id_salas`),
CONSTRAINT `FK_tab_mov_hw_header_lst_tipo_documentos` FOREIGN KEY (`mhwh_fk_tdocumento`) REFERENCES `lst_tipo_documentos` (`id_tdocumentos`)
)
COLLATE='utf8mb4_0900_ai_ci'
ENGINE=InnoDB
AUTO_INCREMENT=55
;
please, let me know if you need some information.
thank youy very much in advace for all your help, jose!





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users