⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

Getting problem with relation_n_n



Carlos Cortes
  • profile picture
  • Member

Posted 30 January 2013 - 23:52 PM

Hi,

I'm starting to use the GC plugin for CI and it is awesome!, but now im getting some error when i try to add a new registry to the database but not when i edit one.
This is the error:

[quote]
[color=#881280][font=Consolas, 'Lucida Console', monospace][size=3]<[/size][/font][/color][color=#881280][font=Consolas, 'Lucida Console', monospace][size=3]p[/size][/font][/color][color=#881280][font=Consolas, 'Lucida Console', monospace][size=3]>[/size][/font][/color][color=#000000][font=Consolas, 'Lucida Console', monospace][size=3]Error Number: 1452[/size][/font][/color][color=#881280][font=Consolas, 'Lucida Console', monospace][size=3]</[/size][/font][/color][color=#881280][font=Consolas, 'Lucida Console', monospace][size=3]p[/size][/font][/color][color=#881280][font=Consolas, 'Lucida Console', monospace][size=3]>[/size][/font][/color][color=#881280][font=Consolas, 'Lucida Console', monospace][size=3]<[/size][/font][/color][color=#881280][font=Consolas, 'Lucida Console', monospace][size=3]p[/size][/font][/color][color=#881280][font=Consolas, 'Lucida Console', monospace][size=3]>[/size][/font][/color][color=#000000][font=Consolas, 'Lucida Console', monospace][size=3]Cannot add or update a child row: a foreign key constraint fails (`josuedor_bd_investigaciones`.`nombre_grupo_has_usuarios`, CONSTRAINT `fk_nombre_grupo_has_invesstigadores_invesstigadores1` FOREIGN KEY (`usuarios_idUsuario`) REFERENCES `usuarios` (`idUsuari)[/size][/font][/color][color=#881280][font=Consolas, 'Lucida Console', monospace][size=3]</[/size][/font][/color][color=#881280][font=Consolas, 'Lucida Console', monospace][size=3]p[/size][/font][/color][color=#881280][font=Consolas, 'Lucida Console', monospace][size=3]>[/size][/font][/color][color=#881280][font=Consolas, 'Lucida Console', monospace][size=3]<[/size][/font][/color][color=#881280][font=Consolas, 'Lucida Console', monospace][size=3]p[/size][/font][/color][color=#881280][font=Consolas, 'Lucida Console', monospace][size=3]>[/size][/font][/color][color=#000000][font=Consolas, 'Lucida Console', monospace][size=3]INSERT INTO `nombre_grupo_has_usuarios` (`usuarios_idUsuario`, `nombre_grupo_idgrupo`) VALUES (0, '111')[/size][/font][/color][color=#881280][font=Consolas, 'Lucida Console', monospace][size=3]</[/size][/font][/color][color=#881280][font=Consolas, 'Lucida Console', monospace][size=3]p[/size][/font][/color][color=#881280][font=Consolas, 'Lucida Console', monospace][size=3]>[/size][/font][/color][color=#881280][font=Consolas, 'Lucida Console', monospace][size=3]<[/size][/font][/color][color=#881280][font=Consolas, 'Lucida Console', monospace][size=3]p[/size][/font][/color][color=#881280][font=Consolas, 'Lucida Console', monospace][size=3]>[/size][/font][/color][color=#000000][font=Consolas, 'Lucida Console', monospace][size=3]Filename: C:\xampp\htdocs\practicas\proyecto-practicas\system\database\DB_driver.php[/size][/font][/color][color=#881280][font=Consolas, 'Lucida Console', monospace][size=3]</[/size][/font][/color][color=#881280][font=Consolas, 'Lucida Console', monospace][size=3]p[/size][/font][/color][color=#881280][font=Consolas, 'Lucida Console', monospace][size=3]>[/size][/font][/color][color=#881280][font=Consolas, 'Lucida Console', monospace][size=3]<[/size][/font][/color][color=#881280][font=Consolas, 'Lucida Console', monospace][size=3]p[/size][/font][/color][color=#881280][font=Consolas, 'Lucida Console', monospace][size=3]>[/size][/font][/color][color=#000000][font=Consolas, 'Lucida Console', monospace][size=3]Line Number: 330[/size][/font][/color][color=#881280][font=Consolas, 'Lucida Console', monospace][size=3]</[/size][/font][/color][color=#881280][font=Consolas, 'Lucida Console', monospace][size=3]p[/size][/font][/color][color=#881280][font=Consolas, 'Lucida Console', monospace][size=3]>[/size][/font][/color][color=#000000][font=Consolas, 'Lucida Console', monospace][size=3] [/size][/font][/color][color=#881280][font=Consolas, 'Lucida Console', monospace][size=3]</[/size][/font][/color][color=#881280][font=Consolas, 'Lucida Console', monospace][size=3]div[/size][/font][/color][color=#881280][font=Consolas, 'Lucida Console', monospace][size=3]>[/size][/font][/color]

[/quote]

And this is the code of the relation:


$crud->set_relation_n_n('grupo','nombre_grupo_has_usuarios','nombre_grupo','usuarios_idUsuario','nombre_grupo_idgrupo','nombre_g');


Just in case, the fields:


$crud->fields('idUsuario','nombre','apellido','direccion','fijo','celular','email','grupo');


Thank you for your help, i had been trying this all day but omg. :unsure:

goFrendiAsgard
  • profile picture
  • Member

Posted 01 February 2013 - 01:45 AM

I've similar problem when using "varchar" field as primary key
Can you make sure that all of your primary key table is "integer" and "auto-increment"?

And, for relation_n_n, have you check this documentation: http://www.grocerycrud.com/documentation/options_functions/set_relation_n_n