1

I'm trying to execute the following SQL command in MySQLWorkbench but it's giving me an error.

Command:

ALTER TABLE `ABC`.`GroupMembers` 
ADD CONSTRAINT `FK_PROFILES`
  FOREIGN KEY ()
  REFERENCES `ABC`.`profiles` ()
  ON DELETE NO ACTION
  ON UPDATE NO ACTION;

Error:

Operation failed: There was an error while applying the SQL script to the database.
ERROR 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 ')
  REFERENCES `ABC`.`profiles` ()
  ON DELETE NO ACTION
  ON UPDATE NO ACTION' at line 3
SQL Statement:
ALTER TABLE `ABC`.`GroupMembers` 
ADD CONSTRAINT `FK_PROFILES`
  FOREIGN KEY ()
  REFERENCES `ABC`.`profiles` ()
  ON DELETE NO ACTION
  ON UPDATE NO ACTION

Not sure what's up. This script was generated by MySQLWorkbench

2 Answers 2

1

There has to be a column (or columns) in both lists. Those can't be empty.

For example:

  FOREIGN KEY (profile_id)
  --           ^^^^^^^^^^
  REFERENCES `ABC`.`profiles` (id)
  --                           ^^

The datatypes of the columns much match exhactly. And values stored in the foreign key column must match the value in a row in the referenced table. (In this example, all values in profile_id must match the value of the id column in the profiles table.

Sign up to request clarification or add additional context in comments.

Comments

1

MYSQL is saying its an syntax issue, and as I can see, there is a couple of things missing in you code.

Please check this link and learn more about the sintaxis in mysql regarding constraints.

Hope it helps.

Edit:

Ok, so just to enforce spencer7593's answer (which should be marked as answer if it solves your issue):

...
/profile_id would be the name you will set to the foreign key
FOREIGN KEY (profile_id) 
...
/The references should be of the same value. 
/`table_name`.`column_name` is the referenced column
/ id is the column on the table which will hold foreign key
REFERENCES `ABC`.`profiles` (id) 

2 Comments

Include the errors and solution in your answer please.
Terribly sorry for that, was trying to encourage him to understand the issue rather then fixing it for him. Wont happen again, thanks for comments.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.