我想在mysql中的表之间建立一些关系。我用gorm orm和go。我有三张table,名字是:singertbl,covertbl,singerscovertbl。我的表具有具有自动递增值的id。在singertbl和covertbl中,我有以下字段:id和{some other field}。在singerscovertbl中,我有以下字段:id,singer\u id,cover\u id。{id.singertbl->singer\u id.singerscovertbl}和{id.covertbl->cover\u id.singerscovertbl}之间有一个关系,当我想在mysql workbench中将此关系作为外键应用于此sql查询时:
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;
我得到这个错误:
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
我怎么能在这两张table之间建立这种关系?!
暂无答案!
目前还没有任何答案,快来回答吧!