Foros del Web » Programación para mayores de 30 ;) » Bases de Datos General » Mysql »

[SOLUCIONADO] [Ayuda]Cannot add or update a child row: a foreign key constraint fails

Estas en el tema de [Ayuda]Cannot add or update a child row: a foreign key constraint fails en el foro de Mysql en Foros del Web. Hola chicos el siguiente error me pasa cuando quiero insertar datos en tabla "dictan".Aca dejo el codigo si me pueden ayudar por favor. @import url("http://static.forosdelweb.com/clientscript/vbulletin_css/geshi.css"); ...
  #1 (permalink)  
Antiguo 06/12/2014, 21:14
 
Fecha de Ingreso: noviembre-2014
Mensajes: 50
Antigüedad: 9 años, 4 meses
Puntos: 0
[Ayuda]Cannot add or update a child row: a foreign key constraint fails

Hola chicos el siguiente error me pasa cuando quiero insertar datos en tabla "dictan".Aca dejo el codigo si me pueden ayudar por favor.
Código MySQL:
Ver original
  1. 'CREATE TABLE `profesor` (\n  `dni` int(11) NOT NULL,\n  `nombre` varchar(45) DEFAULT NULL,\n  `apellido` varchar(45) DEFAULT NULL,\n  `fechaNacimiento` varchar(45) DEFAULT NULL,\n  `lugarNacimiento` varchar(45) DEFAULT NULL,\n  `domicilio` varchar(45) DEFAULT NULL,\n  `mail` varchar(45) DEFAULT NULL,\n  PRIMARY KEY (`dni`)\n) ENGINE=InnoDB DEFAULT CHARSET=latin1'
  2.  
  3.  
  4. 'CREATE TABLE `comision` (\n  `numeroComision` int(11) NOT NULL AUTO_INCREMENT,\n  `dia/s` varchar(45) DEFAULT NULL,\n  `horario` varchar(45) DEFAULT NULL,\n  PRIMARY KEY (`numeroComision`)\n) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=latin1'
  5.  
  6.  
  7.  'CREATE TABLE `dictan` (\n  `dni` int(11) NOT NULL,\n  `numeroComision` int(11) NOT NULL,\n  PRIMARY KEY (`dni`,`numeroComision`),\n  KEY `numeroComision` (`numeroComision`),\n  CONSTRAINT `dictan_ibfk_1` FOREIGN KEY (`dni`) REFERENCES `profesor` (`dni`),\n  CONSTRAINT `dictan_ibfk_2` FOREIGN KEY (`numeroComision`) REFERENCES `comision` (`numeroComision`)\n) ENGINE=InnoDB DEFAULT CHARSET=latin1'
  #2 (permalink)  
Antiguo 06/12/2014, 21:41
 
Fecha de Ingreso: noviembre-2014
Mensajes: 50
Antigüedad: 9 años, 4 meses
Puntos: 0
Respuesta: [Ayuda]Cannot add or update a child row: a foreign key constraint fails

el problema era que una la pk era autoincrement y en la otra no,modifique eso y andubo

Etiquetas: add, child, constraint, key, row, tabla, update
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 19:17.