Question for the #MySQL / #MariaDB buffs, I have three tables defined thus:
Running the last query triggers the error
#SQL #Database #DBA
CREATE TABLE IF NOT EXISTS `user` (
`uid` mediumint unsigned NOT NULL auto_increment COMMENT 'sequential ID',
...
PRIMARY KEY(`uid`)
);
CREATE TABLE IF NOT EXISTS `gserver` (
`id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
...
PRIMARY KEY(`id`)
);
CREATE TABLE IF NOT EXISTS `user-gserver` (
`uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'Owner User id',
`gsid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'Gserver id',
...
PRIMARY KEY(`uid`,`gsid`),
FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE,
FOREIGN KEY (`gsid`) REFERENCES `gserver` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE
);
Running the last query triggers the error
Foreign key constraint is incorrectly formed
. Is there no way to reference multiple tables in foreign keys out of a compound primary key?#SQL #Database #DBA
silverwizard
•So one upvote for "huh, that's dumb"
Hypolite Petovan likes this.
Karl Levik Ⓥ
•Hypolite Petovan likes this.
Hypolite Petovan
•Hypolite Petovan
•`user-gserver`.`gsid`
field type toint unsigned
enabled the creation of the table. 😌Karl Levik Ⓥ
•Hypolite Petovan likes this.