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

me podrian echar una mano...!!

Estas en el tema de me podrian echar una mano...!! en el foro de Bases de Datos General en Foros del Web. el problema resulta al ejecutar la tabla comentario... no veo ningun detalle a simple vista y el script lo genere atraves de workbench..... de antemano ...
  #1 (permalink)  
Antiguo 18/06/2010, 08:58
 
Fecha de Ingreso: octubre-2009
Mensajes: 23
Antigüedad: 14 años, 6 meses
Puntos: 0
me podrian echar una mano...!!

el problema resulta al ejecutar la tabla comentario...

no veo ningun detalle a simple vista y el script lo genere atraves de workbench.....


de antemano gracias por la ayuda


Código:
SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;
SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='TRADITIONAL';

CREATE SCHEMA IF NOT EXISTS `blog` DEFAULT CHARACTER SET latin1 COLLATE latin1_swedish_ci ;

-- -----------------------------------------------------
-- Table `blog`.`categoria`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `blog`.`categoria` (
  `id_categoria` INT NOT NULL AUTO_INCREMENT ,
  `nombre` VARCHAR(45) NULL ,
  `descripcion` VARCHAR(100) NULL ,
  PRIMARY KEY (`id_categoria`) )
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `blog`.`sub_categoria`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `blog`.`sub_categoria` (
  `id_sub_categoria` INT NOT NULL AUTO_INCREMENT ,
  `nombre` VARCHAR(30) NOT NULL ,
  `id_categoria` INT NOT NULL ,
  PRIMARY KEY (`id_sub_categoria`) ,
  INDEX `categoria- sub_catgoria` (`id_categoria` ASC) ,
  CONSTRAINT `categoria- sub_catgoria`
    FOREIGN KEY (`id_categoria` )
    REFERENCES `blog`.`categoria` (`id_categoria` )
    ON DELETE RESTRICT
    ON UPDATE CASCADE)
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `blog`.`publicacion`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `blog`.`publicacion` (
  `id_publicacion` INT NOT NULL AUTO_INCREMENT ,
  `titulo_publicacion` VARCHAR(100) NOT NULL ,
  `texto_publicacion` TEXT NOT NULL ,
  `fecha_publicacion` DATE NOT NULL ,
  `id_sub_categoria` INT NOT NULL ,
  PRIMARY KEY (`id_publicacion`) ,
  INDEX `categoria-publicacion` (`id_sub_categoria` ASC) ,
  CONSTRAINT `categoria-publicacion`
    FOREIGN KEY (`id_sub_categoria` )
    REFERENCES `blog`.`sub_categoria` (`id_sub_categoria` )
    ON DELETE RESTRICT
    ON UPDATE CASCADE)
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `blog`.`imagen`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `blog`.`imagen` (
  `id_imagen` INT NOT NULL AUTO_INCREMENT ,
  `dir_archivo_p` VARCHAR(90) NOT NULL ,
  `dir_imagen_g` VARCHAR(90) NOT NULL ,
  `titulo_imagen` VARCHAR(70) NOT NULL ,
  `id_publicacion` INT NOT NULL ,
  PRIMARY KEY (`id_imagen`) ,
  INDEX `imagen-publicacion` (`id_publicacion` ASC) ,
  CONSTRAINT `imagen-publicacion`
    FOREIGN KEY (`id_publicacion` )
    REFERENCES `blog`.`publicacion` (`id_publicacion` )
    ON DELETE CASCADE
    ON UPDATE CASCADE)
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `blog`.`archivos_externos`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `blog`.`archivos_externos` (
  `id_archivos_externos` INT NOT NULL AUTO_INCREMENT ,
  `dir_archivo` VARCHAR(150) NOT NULL ,
  `titulo` VARCHAR(80) NOT NULL ,
  `tipo` INT NOT NULL ,
  `id_publicacion` INT NOT NULL ,
  PRIMARY KEY (`id_archivos_externos`) ,
  INDEX `archivo-publicacion` (`id_publicacion` ASC) ,
  CONSTRAINT `archivo-publicacion`
    FOREIGN KEY (`id_publicacion` )
    REFERENCES `blog`.`publicacion` (`id_publicacion` )
    ON DELETE CASCADE
    ON UPDATE CASCADE)
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `blog`.`usuario`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `blog`.`usuario` (
  `id_usuario` INT NOT NULL AUTO_INCREMENT ,
  `email` VARCHAR(70) NOT NULL ,
  `clave` VARCHAR(45) NOT NULL ,
  `nombre` VARCHAR(60) NULL ,
  `fecha_nacimiento` VARCHAR(45) NULL ,
  PRIMARY KEY (`id_usuario`) ,
  UNIQUE INDEX `email_UNIQUE` (`email` ASC) )
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `blog`.`comentario`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `blog`.`comentario` (
  `id_comentario` INT NOT NULL AUTO_INCREMENT ,
  `texto_comentario` VARCHAR(255) NOT NULL ,
  `fecha` DATE NOT NULL ,
  `id_usuario` INT NOT NULL ,
  `id_publicacion` INT NOT NULL ,
  PRIMARY KEY (`id_comentario`) ,
  INDEX `comentario-usuario` (`id_usuario` ASC) ,
  INDEX `comentario-publicacion` (`id_publicacion` ASC) ,
  CONSTRAINT `comentario-usuario`
    FOREIGN KEY (`id_usuario` )
    REFERENCES `blog`.`usuario` (`id_usuario` )
    ON DELETE SET NULL
    ON UPDATE CASCADE,
  CONSTRAINT `comentario-publicacion`
    FOREIGN KEY (`id_publicacion` )
    REFERENCES `blog`.`publicacion` (`id_publicacion` )
    ON DELETE CASCADE
    ON UPDATE CASCADE)
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `blog`.`favorito`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `blog`.`favorito` (
  `id_usuario` INT NOT NULL ,
  `id_publicacion` INT NOT NULL ,
  PRIMARY KEY (`id_usuario`, `id_publicacion`) ,
  INDEX `usurio-favorito` (`id_usuario` ASC) ,
  INDEX `favorito-publicacio` (`id_publicacion` ASC) ,
  CONSTRAINT `usurio-favorito`
    FOREIGN KEY (`id_usuario` )
    REFERENCES `blog`.`usuario` (`id_usuario` )
    ON DELETE CASCADE
    ON UPDATE CASCADE,
  CONSTRAINT `favorito-publicacio`
    FOREIGN KEY (`id_publicacion` )
    REFERENCES `blog`.`publicacion` (`id_publicacion` )
    ON DELETE CASCADE
    ON UPDATE CASCADE)
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `blog`.`historial`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `blog`.`historial` (
  `id_historial` INT NOT NULL AUTO_INCREMENT ,
  `id_publicacion` INT NOT NULL ,
  `id_usuario` INT NOT NULL ,
  `fecha_visita` DATE NOT NULL ,
  PRIMARY KEY (`id_historial`) ,
  INDEX `historial-publicacion` (`id_publicacion` ASC) ,
  INDEX `historial-usuario` (`id_usuario` ASC) ,
  CONSTRAINT `historial-publicacion`
    FOREIGN KEY (`id_publicacion` )
    REFERENCES `blog`.`publicacion` (`id_publicacion` )
    ON DELETE CASCADE
    ON UPDATE CASCADE,
  CONSTRAINT `historial-usuario`
    FOREIGN KEY (`id_usuario` )
    REFERENCES `blog`.`usuario` (`id_usuario` )
    ON DELETE SET NULL
    ON UPDATE CASCADE)
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `blog`.`valoracion`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `blog`.`valoracion` (
  `id_usuario` INT NOT NULL ,
  `id_publicacion` INT NOT NULL ,
  `valor_publicacion` INT NOT NULL ,
  PRIMARY KEY (`id_usuario`, `id_publicacion`) ,
  INDEX `usuario-valoracion` (`id_usuario` ASC) ,
  INDEX `valoracion-publicacion` (`id_publicacion` ASC) ,
  CONSTRAINT `usuario-valoracion`
    FOREIGN KEY (`id_usuario` )
    REFERENCES `blog`.`usuario` (`id_usuario` )
    ON DELETE SET NULL
    ON UPDATE CASCADE,
  CONSTRAINT `valoracion-publicacion`
    FOREIGN KEY (`id_publicacion` )
    REFERENCES `blog`.`publicacion` (`id_publicacion` )
    ON DELETE CASCADE
    ON UPDATE CASCADE)
ENGINE = InnoDB;



SET SQL_MODE=@OLD_SQL_MODE;
SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;
  #2 (permalink)  
Antiguo 18/06/2010, 09:25
Avatar de gnzsoloyo
Moderador criollo
 
Fecha de Ingreso: noviembre-2007
Ubicación: Actualmente en Buenos Aires (el enemigo ancestral)
Mensajes: 23.324
Antigüedad: 16 años, 5 meses
Puntos: 2658
Respuesta: me podrian echar una mano...!!

Gracias por postear el script. Eso lo hizo más fácil.
El problema está las cláusulas ON DELETE y ON UPDATE, porque en tres tablas una de ellas decía SET NULL, lo que era imposible porque el campo usado como FK estaba declarado como NOT NULL.
Un simple problema de lógica.

Código MySQL:
Ver original
  1. SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;
  2. SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
  3. SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='TRADITIONAL';
  4.  
  5. CREATE SCHEMA IF NOT EXISTS `blog` DEFAULT CHARACTER SET latin1 COLLATE latin1_swedish_ci ;
  6.  
  7. -- -----------------------------------------------------
  8. -- Table `blog`.`categoria`
  9. -- -----------------------------------------------------
  10. CREATE  TABLE IF NOT EXISTS `blog`.`categoria` (
  11.   `id_categoria` INT NOT NULL AUTO_INCREMENT ,
  12.   `nombre` VARCHAR(45) NULL ,
  13.   `descripcion` VARCHAR(100) NULL ,
  14.   PRIMARY KEY (`id_categoria`) )
  15.  
  16.  
  17. -- -----------------------------------------------------
  18. -- Table `blog`.`sub_categoria`
  19. -- -----------------------------------------------------
  20. CREATE  TABLE IF NOT EXISTS `blog`.`sub_categoria` (
  21.   `id_sub_categoria` INT NOT NULL AUTO_INCREMENT ,
  22.   `nombre` VARCHAR(30) NOT NULL ,
  23.   `id_categoria` INT NOT NULL ,
  24.   PRIMARY KEY (`id_sub_categoria`) ,
  25.   INDEX `categoria- sub_catgoria` (`id_categoria` ASC) ,
  26.   CONSTRAINT `categoria- sub_catgoria`
  27.     FOREIGN KEY (`id_categoria` )
  28.     REFERENCES `blog`.`categoria` (`id_categoria` )
  29.  
  30.  
  31. -- -----------------------------------------------------
  32. -- Table `blog`.`publicacion`
  33. -- -----------------------------------------------------
  34. CREATE  TABLE IF NOT EXISTS `blog`.`publicacion` (
  35.   `id_publicacion` INT NOT NULL AUTO_INCREMENT ,
  36.   `titulo_publicacion` VARCHAR(100) NOT NULL ,
  37.   `texto_publicacion` TEXT NOT NULL ,
  38.   `fecha_publicacion` DATE NOT NULL ,
  39.   `id_sub_categoria` INT NOT NULL ,
  40.   PRIMARY KEY (`id_publicacion`) ,
  41.   INDEX `categoria-publicacion` (`id_sub_categoria` ASC) ,
  42.   CONSTRAINT `categoria-publicacion`
  43.     FOREIGN KEY (`id_sub_categoria` )
  44.     REFERENCES `blog`.`sub_categoria` (`id_sub_categoria` )
  45.  
  46.  
  47. -- -----------------------------------------------------
  48. -- Table `blog`.`imagen`
  49. -- -----------------------------------------------------
  50. CREATE  TABLE IF NOT EXISTS `blog`.`imagen` (
  51.   `id_imagen` INT NOT NULL AUTO_INCREMENT ,
  52.   `dir_archivo_p` VARCHAR(90) NOT NULL ,
  53.   `dir_imagen_g` VARCHAR(90) NOT NULL ,
  54.   `titulo_imagen` VARCHAR(70) NOT NULL ,
  55.   `id_publicacion` INT NOT NULL ,
  56.   PRIMARY KEY (`id_imagen`) ,
  57.   INDEX `imagen-publicacion` (`id_publicacion` ASC) ,
  58.   CONSTRAINT `imagen-publicacion`
  59.     FOREIGN KEY (`id_publicacion` )
  60.     REFERENCES `blog`.`publicacion` (`id_publicacion` )
  61.  
  62.  
  63. -- -----------------------------------------------------
  64. -- Table `blog`.`archivos_externos`
  65. -- -----------------------------------------------------
  66. CREATE  TABLE IF NOT EXISTS `blog`.`archivos_externos` (
  67.   `id_archivos_externos` INT NOT NULL AUTO_INCREMENT ,
  68.   `dir_archivo` VARCHAR(150) NOT NULL ,
  69.   `titulo` VARCHAR(80) NOT NULL ,
  70.   `tipo` INT NOT NULL ,
  71.   `id_publicacion` INT NOT NULL ,
  72.   PRIMARY KEY (`id_archivos_externos`) ,
  73.   INDEX `archivo-publicacion` (`id_publicacion` ASC) ,
  74.   CONSTRAINT `archivo-publicacion`
  75.     FOREIGN KEY (`id_publicacion` )
  76.     REFERENCES `blog`.`publicacion` (`id_publicacion` )
  77.  
  78.  
  79. -- -----------------------------------------------------
  80. -- Table `blog`.`usuario`
  81. -- -----------------------------------------------------
  82. CREATE  TABLE IF NOT EXISTS `blog`.`usuario` (
  83.   `id_usuario` INT NOT NULL AUTO_INCREMENT ,
  84.   `email` VARCHAR(70) NOT NULL ,
  85.   `clave` VARCHAR(45) NOT NULL ,
  86.   `nombre` VARCHAR(60) NULL ,
  87.   `fecha_nacimiento` VARCHAR(45) NULL ,
  88.   PRIMARY KEY (`id_usuario`) ,
  89.   UNIQUE INDEX `email_UNIQUE` (`email` ASC) )
  90.  
  91.  
  92. -- -----------------------------------------------------
  93. -- Table `blog`.`comentario`
  94. -- -----------------------------------------------------
  95. CREATE  TABLE IF NOT EXISTS `blog`.`comentario` (
  96.   `id_comentario` INT NOT NULL AUTO_INCREMENT ,
  97.   `texto_comentario` VARCHAR(255) NOT NULL ,
  98.   `fecha` DATE NOT NULL ,
  99.   `id_usuario` INT NOT NULL ,
  100.   `id_publicacion` INT NOT NULL ,
  101.   PRIMARY KEY (`id_comentario`) ,
  102.   INDEX `comentario-usuario` (`id_usuario` ASC) ,
  103.   INDEX `comentario-publicacion` (`id_publicacion` ASC) ,
  104.   CONSTRAINT `comentario-usuario`
  105.     FOREIGN KEY (`id_usuario` )
  106.     REFERENCES `blog`.`usuario` (`id_usuario` )
  107.   CONSTRAINT `comentario-publicacion`
  108.     FOREIGN KEY (`id_publicacion` )
  109.     REFERENCES `blog`.`publicacion` (`id_publicacion` )
  110.  
  111.  
  112. -- -----------------------------------------------------
  113. -- Table `blog`.`favorito`
  114. -- -----------------------------------------------------
  115. CREATE  TABLE IF NOT EXISTS `blog`.`favorito` (
  116.   `id_usuario` INT NOT NULL ,
  117.   `id_publicacion` INT NOT NULL ,
  118.   PRIMARY KEY (`id_usuario`, `id_publicacion`) ,
  119.   INDEX `usurio-favorito` (`id_usuario` ASC) ,
  120.   INDEX `favorito-publicacio` (`id_publicacion` ASC) ,
  121.   CONSTRAINT `usurio-favorito`
  122.     FOREIGN KEY (`id_usuario` )
  123.     REFERENCES `blog`.`usuario` (`id_usuario` )
  124.   CONSTRAINT `favorito-publicacio`
  125.     FOREIGN KEY (`id_publicacion` )
  126.     REFERENCES `blog`.`publicacion` (`id_publicacion` )
  127.  
  128.  
  129. -- -----------------------------------------------------
  130. -- Table `blog`.`historial`
  131. -- -----------------------------------------------------
  132. CREATE  TABLE IF NOT EXISTS `blog`.`historial` (
  133.   `id_historial` INT NOT NULL AUTO_INCREMENT ,
  134.   `id_publicacion` INT NOT NULL ,
  135.   `id_usuario` INT NOT NULL ,
  136.   `fecha_visita` DATE NOT NULL ,
  137.   PRIMARY KEY (`id_historial`) ,
  138.   INDEX `historial-publicacion` (`id_publicacion` ASC) ,
  139.   INDEX `historial-usuario` (`id_usuario` ASC) ,
  140.   CONSTRAINT `historial-publicacion`
  141.     FOREIGN KEY (`id_publicacion` )
  142.     REFERENCES `blog`.`publicacion` (`id_publicacion` )
  143.   CONSTRAINT `historial-usuario`
  144.     FOREIGN KEY (`id_usuario` )
  145.     REFERENCES `blog`.`usuario` (`id_usuario` )
  146.  
  147.  
  148. -- -----------------------------------------------------
  149. -- Table `blog`.`valoracion`
  150. -- -----------------------------------------------------
  151. CREATE  TABLE IF NOT EXISTS `blog`.`valoracion` (
  152.   `id_usuario` INT NOT NULL ,
  153.   `id_publicacion` INT NOT NULL ,
  154.   `valor_publicacion` INT NOT NULL ,
  155.   PRIMARY KEY (`id_usuario`, `id_publicacion`) ,
  156.   INDEX `usuario-valoracion` (`id_usuario` ASC) ,
  157.   INDEX `valoracion-publicacion` (`id_publicacion` ASC) ,
  158.   CONSTRAINT `usuario-valoracion`
  159.     FOREIGN KEY (`id_usuario` )
  160.     REFERENCES `blog`.`usuario` (`id_usuario` )
  161.   CONSTRAINT `valoracion-publicacion`
  162.     FOREIGN KEY (`id_publicacion` )
  163.     REFERENCES `blog`.`publicacion` (`id_publicacion` )
  164.  
  165.  
  166.  
  167. SET SQL_MODE=@OLD_SQL_MODE;
  168. SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
  169. SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;
__________________
¿A quién le enseñan sus aciertos?, si yo aprendo de mis errores constantemente...
"El problema es la interfase silla-teclado." (Gillermo Luque)
  #3 (permalink)  
Antiguo 18/06/2010, 09:57
 
Fecha de Ingreso: octubre-2009
Mensajes: 23
Antigüedad: 14 años, 6 meses
Puntos: 0
Respuesta: me podrian echar una mano...!!

GRACIAS...!!!

por tu ayuda....

Etiquetas: mano
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 08:38.