drqvsx1228 2018-11-03 08:07 采纳率: 0%
浏览 106

如何在MySQL中建立表之间的关系

I want to have some relation between my tables in MySQL. I use GORM ORM and go. I have 3 table with this name: singertbl, covertbl, singerscovertbl. my tables have id with autoincrement value. in singertbl and covertbl, I have this fields: ID and {some another field}. and in singerscovertbl I have this fields: ID, singer_id, cover_id. there is a relation between {ID.singertbl -> singer_id.singerscovertbl} and {ID.covertbl -> cover_id.singerscovertbl} when I want to apply this relation as a foreign key in MySQL workbench with this SQL query:

    ALTER TABLE `mskm`.`albumscovers` 
ADD INDEX `ID_idx` (`album_id` ASC) VISIBLE,
ADD INDEX `ID_idx1` (`cover_id` ASC) VISIBLE;
;
ALTER TABLE `mskm`.`albumscovers` 
ADD CONSTRAINT `ID`
  FOREIGN KEY (`album_id`)
  REFERENCES `mskm`.`albumstbls` (`ID`)
  ON DELETE NO ACTION
  ON UPDATE NO ACTION;

I get this error:

 Operation failed: There was an error while applying the SQL script to the database.
Executing:
ALTER TABLE `mskm`.`albumscovers` 
ADD INDEX `ID_idx` (`album_id` ASC) VISIBLE,
ADD INDEX `ID_idx1` (`cover_id` ASC) VISIBLE;
;
ALTER TABLE `mskm`.`albumscovers` 
ADD CONSTRAINT `ID`
  FOREIGN KEY (`album_id`)
  REFERENCES `mskm`.`albumstbls` (`ID`)
  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 `ID_idx1` (`cover_id` ASC) VISIBLE' at line 2
SQL Statement:
ALTER TABLE `mskm`.`albumscovers` 
ADD INDEX `ID_idx` (`album_id` ASC) VISIBLE,
ADD INDEX `ID_idx1` (`cover_id` ASC) VISIBLE

how I can make this relationship between this tables?!

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 目详情-五一模拟赛详情页
    • ¥15 有了解d3和topogram.js库的吗?有偿请教
    • ¥100 任意维数的K均值聚类
    • ¥15 stamps做sbas-insar,时序沉降图怎么画
    • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
    • ¥15 关于#Java#的问题,如何解决?
    • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
    • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
    • ¥15 cmd cl 0x000007b
    • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line