Mysql Workbench error setting foreign keys

Asked

Viewed 253 times

0

I am wanting to create two foreign keys through Mysql Workbench and when I apply the information it executes the code below:

ALTER TABLE `insect_db`.`usu_ins` 
ADD INDEX `fk_id_ins_idx` (`id_ins` ASC) VISIBLE,
ADD INDEX `fk_id_cad_idx` (`id_cad` ASC) VISIBLE;
;
ALTER TABLE `insect_db`.`usu_ins` 
ADD CONSTRAINT `fk_id_ins`
  FOREIGN KEY (`id_ins`)
  REFERENCES `insect_db`.`insects` (`entry_cod`)
  ON DELETE NO ACTION
  ON UPDATE NO ACTION,
ADD CONSTRAINT `fk_id_cad`
  FOREIGN KEY (`id_cad`)
  REFERENCES `insect_db`.`cadastro` (`entry_cod`)
  ON DELETE NO ACTION
  ON UPDATE NO ACTION;

However, follow the error below:

Operation failed: There was an error while applying the SQL script to the database.
Executing:
ALTER TABLE `insect_db`.`usu_ins` 
ADD INDEX `fk_id_ins_idx` (`id_ins` ASC) VISIBLE,
ADD INDEX `fk_id_cad_idx` (`id_cad` ASC) VISIBLE;
;
ALTER TABLE `insect_db`.`usu_ins` 
ADD CONSTRAINT `fk_id_ins`
  FOREIGN KEY (`id_ins`)
  REFERENCES `insect_db`.`insects` (`entry_cod`)
  ON DELETE NO ACTION
  ON UPDATE NO ACTION,
ADD CONSTRAINT `fk_id_cad`
  FOREIGN KEY (`id_cad`)
  REFERENCES `insect_db`.`cadastro` (`entry_cod`)
  ON DELETE NO ACTION
  ON UPDATE NO ACTION;

ERROR 1064: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '
ADD INDEX `fk_id_cad_idx` (`id_cad` ASC) VISIBLE' at line 2
SQL Statement:
ALTER TABLE `insect_db`.`usu_ins` 
ADD INDEX `fk_id_ins_idx` (`id_ins` ASC) VISIBLE,
ADD INDEX `fk_id_cad_idx` (`id_cad` ASC) VISIBLE

I tried to find some solution, but nothing came up. What to do?

  • 1

    The problem is not that comma on line 2?

  • It also has two dots and commas on lines 3 and 4

  • No, the error continues.

  • I was able to resolve by removing the VISIBLE terms on lines 2 and 3.

1 answer

0

try to create the keys separately:

Alter table usu_ins add constraint fk_id_ins foreign key (id_ins) references insects(entry_cod);

Alter table usu_ins add constraint fk_id_cad foreign key (id_cad) references cadastro(entry_cod);

Browser other questions tagged

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