#1215 - You cannot add a foreign key constraint

Asked

Viewed 213 times

0

Good night,

I can’t figure out why error #1215. I’m a few hours away and still can’t figure it out. Can anyone help me? Thanks!

CREATE TABLE IF NOT EXISTS `imovelweb`.`cadastro` (
      `id_cadastro` INT NOT NULL AUTO_INCREMENT,
      `empresa` VARCHAR(45) NULL,
      `cnpj` VARCHAR(45) NULL,
      `razao_social` VARCHAR(45) NULL,
      `endereco` VARCHAR(45) NULL,
      `numero` VARCHAR(45) NULL,
      `complemento` VARCHAR(45) NULL,
      `bairro` VARCHAR(45) NULL,
      `cidade` VARCHAR(45) NULL,
      `estado` VARCHAR(45) NULL,
      `cep` VARCHAR(45) NULL,
      PRIMARY KEY (`id_cadastro`))
    ENGINE = InnoDB;

    CREATE TABLE IF NOT EXISTS `imovelweb`.`imoveis` (
      `id_imoveis` INT NOT NULL AUTO_INCREMENT,
      `titulo` VARCHAR(255) NULL,
      `descricao` LONGTEXT NULL,
      `area_util` VARCHAR(45) NULL,
      `area_cons` VARCHAR(45) NULL,
      `quartos` INT NULL,
      `banheiros` INT NULL,
      `vagas` INT NULL,
      `logo` BLOB NULL,
      `valor` DOUBLE NULL,
      `id_cadastro` INT NOT NULL,
       PRIMARY KEY (`id_imoveis`, `id_cadastro`),
       CONSTRAINT `fk_imoveis_cadastro`
       FOREIGN KEY (`id_cadastro`)
       REFERENCES `webimoveis`.`cadastro` (`id_cadastro`)
       ON DELETE NO ACTION
       ON UPDATE NO ACTION)
    ENGINE = InnoDB
  • 1

    Are you sure this is it: REFERENCES webimoveis.cadastro (id_cadastro) or should be: REFERENCES imovelweb.cadastro (id_cadastro)? Maybe the wrong comic book name?

  • REFERENCES webimoveis.cadastro (id_cadastro). I forgot to change the name of the comic. Now it works. Thank you!

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.