1

I have two tables that look like the following:

http://pastebin.com/AwRJJiPE

I am then trying to add a foreign key constraint like so:

mysql> ALTER TABLE `Order`
    -> ADD CONSTRAINT `FK_baseline_order`
    ->     FOREIGN KEY `baselineId`
    ->     REFERENCES `Baseline` (`id`)
    ->     ON UPDATE CASCADE ON DELETE CASCADE;

I get the following "syntax" error:

ERROR 1064 (42000): 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 'REFERENCES Baseline (id) ON UPDATE CASCADE ON DELETE CASCADE' at line 4

I for the life of me can't figure out what I'm doing wrong. I feel like I'm missing something really obvious here...

1
  • Deleted my answer, I misread the error Commented Feb 6, 2014 at 22:02

2 Answers 2

3

You need to put the referencing columns between parenthesis as well:

ALTER TABLE `Order`
   ADD CONSTRAINT `FK_baseline_order`
      FOREIGN KEY (`baselineId`)     <<<<-- here
      REFERENCES `Baseline` (`id`)
      ON UPDATE CASCADE ON DELETE CASCADE;
Sign up to request clarification or add additional context in comments.

Comments

0

Try putting your foriegn key column inside parenthesis like

ALTER TABLE `Order`
 ADD CONSTRAINT `FK_baseline_order`
     FOREIGN KEY (`baselineId`) <-- Here
    REFERENCES `Baseline` (`id`)
     ON UPDATE CASCADE ON DELETE CASCADE;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.