尝试使表中的一列引用另一表中的另一列时,我不断收到以下错误。

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FOREIGN KEY (campaignid) REFERENCES campaigns(id)' at line 1


在这种情况下,我要在表“页面”中引用“ = campaignid”列(对表“ campaigns”引用“ =”列)。

ALTER TABLE pages FOREIGN KEY (campaignid) REFERENCES campaigns(id)


谁能看到我要去哪里错了?

提前致谢!

最佳答案

您错过了我想的ADD关键字(MySQL docu):

ALTER TABLE pages ADD FOREIGN KEY (campaignid) REFERENCES campaigns(id);

10-04 10:34