简体   繁体   中英

MySQL 1005 Error - What's wrong with the query?

I'm unable to see the issue with this CREATE TABLE sentences. I've double checked but can't find the error.

-- -----------------------------------------------------
-- Table `agentes`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `agentes` (
  `id` INT(11) NOT NULL AUTO_INCREMENT ,
  `codAgente` VARCHAR(8) NOT NULL ,
  `clave` VARCHAR(8) NOT NULL ,
  `nombre` VARCHAR(50) NOT NULL ,
  `apellido1` VARCHAR(50) NOT NULL ,
  `apellido2` VARCHAR(50) NOT NULL ,
  `email` VARCHAR(100) NOT NULL ,
  `usuarioDA` VARCHAR(45) NULL ,
  `passDA` VARCHAR(100) NULL ,
  PRIMARY KEY (`id`) )
ENGINE = InnoDB
COLLATE = latin1_spanish_ci;

-- -----------------------------------------------------
-- Table `cola`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `colas` (
  `idCola` INT NOT NULL AUTO_INCREMENT ,
  `cliente` INT NOT NULL ,
  `nombre` VARCHAR(45) NOT NULL ,
  PRIMARY KEY (`idCola`) ,
  INDEX `fk_colas_clientes1` (`cliente` ASC) ,
  CONSTRAINT `fk_colas_clientes1`
    FOREIGN KEY (`cliente` )
    REFERENCES `clientes` (`idCliente` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `relColaExt`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `relColaExt` (
  `id` INT NOT NULL AUTO_INCREMENT ,
  `codAgente` VARCHAR(8) NOT NULL ,
  `cola` VARCHAR(45) NOT NULL ,
  `prioridad` INT NOT NULL ,
  PRIMARY KEY (`id`) ,
  UNIQUE INDEX `id` (`id` ASC) ,
  INDEX `fk_relColaExt_agentes1` (`codAgente` ASC) ,
  INDEX `fk_relColaExt_colas1` (`cola` ASC) ,
  CONSTRAINT `fk_relColaExt_agentes1`
    FOREIGN KEY (`codAgente` )
    REFERENCES `agentes` (`codAgente` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `fk_relColaExt_colas1`
    FOREIGN KEY (`cola` )
    REFERENCES `colas` (`nombre` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB;

It throws #1005 - Can't create table './centralita/relColaExt.frm' (errno: 150) creating the relColaExt table.

It's a Foreign Key issue but I'm not able to see what's wrong. Can someone help me, please?

According to this comment on MySQL manual page on Foreign keys, it may be due to different encoding of the VARCHAR columns. In table agentes you defined a collation but in relColaExt you did not.

Try using the same collation on every table (by defining it or by letting the default kick in).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM