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

Error al insertar con clave foránea - Cannot add or update a child row

Estas en el tema de Error al insertar con clave foránea - Cannot add or update a child row en el foro de Mysql en Foros del Web. Perdonadme si e suan tonteria pero es que no encuentro el fallo :( aver si lo veis vosotros: Error: Cannot add or update a child ...
  #1 (permalink)  
Antiguo 11/03/2008, 05:35
 
Fecha de Ingreso: diciembre-2007
Mensajes: 149
Antigüedad: 16 años, 4 meses
Puntos: 1
Error al insertar con clave foránea - Cannot add or update a child row

Perdonadme si e suan tonteria pero es que no encuentro el fallo :( aver si lo veis vosotros:

Error: Cannot add or update a child row: a foreign key constraint fails

Se que no estoy haciendo bién la inserccion por algun dato que falte o sobre, pero es que ya no lo veo :(

La inserccion es:

INSERT INTO `cliente_evento` (`titulo_evento_cliente`,`nombre_cliente`,`apellid o_1_cliente`,`apellido_2_cliente`,`estado`) VALUES ('EVENTO 1','Felix','Manzaneda','Vallejo',0)

Y la estructura de mis tablas, la he exportado para que se vean tambien los datos:

--
-- Estructura de tabla para la tabla `bannerinf`
--

DROP TABLE IF EXISTS `bannerinf`;
CREATE TABLE `bannerinf` (
`idbanner` int(11) NOT NULL auto_increment,
`anunciante` varchar(100) default NULL,
`banner` varchar(100) default NULL,
`url` varchar(255) default NULL,
`hits` int(11) unsigned default NULL,
`orden` int(11) NOT NULL default '999',
`estado` tinyint(3) unsigned default '0',
PRIMARY KEY (`idbanner`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

--
-- Volcar la base de datos para la tabla `bannerinf`
--


-- --------------------------------------------------------

--
-- Estructura de tabla para la tabla `bannersup`
--

DROP TABLE IF EXISTS `bannersup`;
CREATE TABLE `bannersup` (
`idbanner` int(11) NOT NULL auto_increment,
`anunciante` varchar(100) default NULL,
`banner` varchar(100) default NULL,
`url` varchar(255) default NULL,
`hits` int(11) unsigned default NULL,
`orden` int(11) NOT NULL default '999',
`estado` tinyint(3) unsigned default '0',
PRIMARY KEY (`idbanner`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

--
-- Volcar la base de datos para la tabla `bannersup`
--


-- --------------------------------------------------------

--
-- Estructura de tabla para la tabla `categorias`
--

DROP TABLE IF EXISTS `categorias`;
CREATE TABLE `categorias` (
`id_categoria` int(11) NOT NULL auto_increment,
`titulo` varchar(64) NOT NULL default '',
`descripcion` text NOT NULL,
PRIMARY KEY (`id_categoria`),
KEY `titulo` (`titulo`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ;

--
-- Volcar la base de datos para la tabla `categorias`
--

INSERT INTO `categorias` VALUES (1, 'CATEGORIA 1', 'sa');

-- --------------------------------------------------------

--
-- Estructura de tabla para la tabla `clientes`
--

DROP TABLE IF EXISTS `clientes`;
CREATE TABLE `clientes` (
`id_cliente` int(11) NOT NULL auto_increment,
`nombre` varchar(64) NOT NULL default '',
`apellido_1` varchar(64) NOT NULL default '',
`apellido_2` varchar(64) NOT NULL default '',
`direccion` varchar(32) NOT NULL default '',
`cp` int(9) unsigned NOT NULL default '0',
`cif` varchar(9) NOT NULL default '',
`empresa` varchar(64) NOT NULL default '',
`localidad` varchar(32) NOT NULL default '',
`provincia` varchar(32) NOT NULL default '',
`telefono` int(32) NOT NULL default '0',
`web` varchar(255) default NULL,
`email` varchar(50) NOT NULL default '',
`modalidad` varchar(30) NOT NULL default '',
`duracion` int(12) NOT NULL default '0',
`fecha` date NOT NULL default '0000-00-00',
`tipo_cliente` varchar(25) NOT NULL default '',
`forma_de_pago` varchar(50) default NULL,
`precio_edicion` int(11) unsigned default NULL,
`iva` int(11) unsigned default '0',
`importe_total` int(32) unsigned default '0',
`banco` int(32) default NULL,
`sucursal` int(32) default NULL,
`dc` int(2) default NULL,
`cc` int(32) default NULL,
`estado` tinyint(3) unsigned default '0',
PRIMARY KEY (`id_cliente`),
KEY `nombre` (`nombre`),
KEY `apellido_1` (`apellido_1`),
KEY `apellido_2` (`apellido_2`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ;

--
-- Volcar la base de datos para la tabla `clientes`
--

INSERT INTO `clientes` VALUES (1, 'Felix', 'Manzaneda', 'Vallejo', 'asasasa', 23445, '77803893E', 'eee', 'asasa', 'asasas', 677769088, NULL, '[email protected]', 'Portada', 2, '2008-04-12', 'Institución', NULL, NULL, 0, 0, NULL, NULL, NULL, NULL, 0);

-- --------------------------------------------------------

--
-- Estructura de tabla para la tabla `cliente_evento`
--

DROP TABLE IF EXISTS `cliente_evento`;
CREATE TABLE `cliente_evento` (
`id_principal_cliente_evento` int(11) NOT NULL auto_increment,
`titulo_evento_cliente` varchar(64) NOT NULL default '',
`nombre_cliente` varchar(64) NOT NULL default '',
`apellido_1_cliente` varchar(64) NOT NULL default '',
`apellido_2_cliente` varchar(64) NOT NULL default '',
`estado` tinyint(3) unsigned default '0',
PRIMARY KEY (`id_principal_cliente_evento`),
KEY `titulo_evento_cliente` (`titulo_evento_cliente`),
KEY `nombre_cliente` (`nombre_cliente`),
KEY `apellido_1_cliente` (`apellido_1_cliente`),
KEY `apellido_2_cliente` (`apellido_2_cliente`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

--
-- Volcar la base de datos para la tabla `cliente_evento`
--


-- --------------------------------------------------------

--
-- Estructura de tabla para la tabla `eventos`
--

DROP TABLE IF EXISTS `eventos`;
CREATE TABLE `eventos` (
`id_evento` int(11) NOT NULL auto_increment,
`titulo` varchar(64) NOT NULL default '',
`descripcion` text NOT NULL,
`titulo_categoria` varchar(64) NOT NULL default '',
`fecha_inicio` date NOT NULL default '0000-00-00',
`fecha_final` date default NULL,
`lugar_celebracion` text NOT NULL,
`precio_entrada` int(32) unsigned default '0',
`email` varchar(32) NOT NULL default '',
`telefono` varchar(32) NOT NULL default '',
`hora_inicio` time default NULL,
`hora_final` time default NULL,
`imagen` varchar(32) NOT NULL default '',
PRIMARY KEY (`id_evento`),
KEY `titulo` (`titulo`),
KEY `titulo_categoria` (`titulo_categoria`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ;

--
-- Volcar la base de datos para la tabla `eventos`
--

INSERT INTO `eventos` VALUES (1, 'CINE', 'ddsad', 'CATEGORIA 1', '2008-06-12', NULL, 'dsada', 0, '[email protected]', '677769088', NULL, NULL, '02.jpg');

--
-- Filtros para las tablas descargadas (dump)
--

--
-- Filtros para la tabla `cliente_evento`
--
ALTER TABLE `cliente_evento`
ADD CONSTRAINT `cliente_evento_ibfk_1` FOREIGN KEY (`titulo_evento_cliente`) REFERENCES `eventos` (`titulo`) ON DELETE CASCADE ON UPDATE CASCADE,
ADD CONSTRAINT `cliente_evento_ibfk_2` FOREIGN KEY (`nombre_cliente`) REFERENCES `clientes` (`nombre`) ON DELETE CASCADE ON UPDATE CASCADE,
ADD CONSTRAINT `cliente_evento_ibfk_3` FOREIGN KEY (`apellido_1_cliente`) REFERENCES `clientes` (`apellido_1`) ON DELETE CASCADE ON UPDATE CASCADE,
ADD CONSTRAINT `cliente_evento_ibfk_4` FOREIGN KEY (`apellido_2_cliente`) REFERENCES `clientes` (`apellido_2`) ON DELETE CASCADE ON UPDATE CASCADE;

--
-- Filtros para la tabla `eventos`
--
ALTER TABLE `eventos`
ADD CONSTRAINT `eventos_ibfk_1` FOREIGN KEY (`titulo_categoria`) REFERENCES `categorias` (`titulo`) ON DELETE CASCADE ON UPDATE CASCADE;
  #2 (permalink)  
Antiguo 11/03/2008, 05:41
 
Fecha de Ingreso: diciembre-2007
Mensajes: 149
Antigüedad: 16 años, 4 meses
Puntos: 1
De acuerdo Re: Error al insertar con clave foránea - Cannot add or update a child row

Lo ví, el valor que insertaba no correspondía con el del campo foráneo al que hacía referencia

INSERT INTO `cliente_evento` (`titulo_evento_cliente`,`nombre_cliente`,`apellid o_1_cliente`,`apellido_2_cliente`,`estado`) VALUES ('CINE','Felix','Manzaneda','Vallejo',0)

La solucion del café, ir y volver, si alguien le pasa ya lo sabe.
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 03:28.