As I have searched, it is a common error and for each case the solution is different. I'm new in database designing. But what is strange to me is that this error is given to me because of running an automatic SQL command generated by MySQL Workbench!
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 ') ,
CONSTRAINT `officialLanguage`
FOREIGN KEY ()
REFERENCES `mydb`.`la' at line 9
SQL Statement:
CREATE TABLE `mydb`.`countries` (
`id` INT NOT NULL AUTO_INCREMENT ,
`name` VARCHAR(50) NULL ,
`shortName` VARCHAR(10) NULL ,
`nativeName` VARCHAR(45) NULL ,
`url` VARCHAR(80) NULL ,
`countryCode` VARCHAR(10) NULL ,
PRIMARY KEY (`id`) ,
INDEX `officialLanguage` () ,
CONSTRAINT `officialLanguage`
FOREIGN KEY ()
REFERENCES `mydb`.`languages` ()
ON DELETE NO ACTION
ON UPDATE NO ACTION);
each part I change or remove does not solve the issue.
It is the second table.
for the first table that had no foreign key, I had no problem:
CREATE TABLE `mydb`.`languages` (
`id` INT NOT NULL AUTO_INCREMENT ,
`name` VARCHAR(20) NULL ,
`shortName` VARCHAR(10) NULL ,
`nativeName` VARCHAR(30) NULL ,
PRIMARY KEY (`id`) );
Solved thanks to Ed Gibbs
I was thinking I was the blamable!
CREATE TABLE `mydb`.`countries` (
`id` INT NOT NULL AUTO_INCREMENT ,
`name` VARCHAR(50) NULL ,
`shortName` VARCHAR(10) NULL ,
`nativeName` VARCHAR(45) NULL ,
`url` VARCHAR(80) NULL ,
`countryCode` VARCHAR(10) NULL ,
`officialLanguage` INT NOT NULL ,
PRIMARY KEY (`id`) ,
INDEX `officialLanguage` (`officialLanguage`) ,
CONSTRAINT `officialLanguage`
FOREIGN KEY (`officialLanguage`)
REFERENCES `mydb`.`languages` (`id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION);