[英]MySQL Error 1064 when creating foreign key
I created this using MySQL WorkBench 我使用MySQL WorkBench创建的
ALTER TABLE `android_marketplace`.`ban_utilizator`
DROP INDEX ,
ADD INDEX `ban_utilizator_id_utilizator_idx` (`id_utilizator` ASC);
ALTER TABLE `android_marketplace`.`ban_utilizator`
ADD CONSTRAINT `ban_utilizator_id_utilizator`
FOREIGN KEY (`id_utilizator`)
REFERENCES `android_marketplace`.`utilizatori` (`id_utilizator`)
ON DELETE NO ACTION
ON UPDATE NO ACTION;
I am getting this : 我得到这个:
Operation failed: There was an error while applying the SQL script to the
database.
Executing:
ALTER TABLE `android_marketplace`.`ban_utilizator`
DROP INDEX ,
ADD INDEX `ban_utilizator_id_utilizator_idx` (`id_utilizator` ASC);
ALTER TABLE `android_marketplace`.`ban_utilizator`
ADD CONSTRAINT `ban_utilizator_id_utilizator`
FOREIGN KEY (`id_utilizator`)
REFERENCES `android_marketplace`.`utilizatori` (`id_utilizator`)
ON DELETE NO ACTION
ON UPDATE NO ACTION;
ERROR 1064: You have an error in your SQL syntax; check the manual that
corresponds to your MariaDB server version for the right syntax to use near '
ADD INDEX `ban_utilizator_id_utilizator_idx` (`id_utilizator` ASC)' at line 2
SQL Statement:
ALTER TABLE `android_marketplace`.`ban_utilizator`
DROP INDEX ,
ADD INDEX `ban_utilizator_id_utilizator_idx` (`id_utilizator` ASC)
The error has nothing to do with a foreign key. 该错误与外键无关。
You must name the index you want to drop. 您必须命名要删除的索引。
Syntax error messages include the context of the problem. 语法错误消息包括问题的上下文。 If the syntax error says: 如果语法错误显示:
check ... for the right syntax to use near ' ADD INDEX
ban_utilizator_id_utilizator_idx
(id_utilizator
ASC)' 检查...以在'ADD INDEXban_utilizator_id_utilizator_idx
(id_utilizator
ASC)附近使用正确的语法
This means the syntax was expecting to find something else at the point where you provided ADD INDEX
. 这意味着该语法希望在您提供ADD INDEX
的位置找到其他内容。
In this case, it was expecting a name for the index you tried to drop in the clause immediately preceding ADD INDEX
. 在这种情况下,期望您尝试在紧邻ADD INDEX
的子句中删除的索引的名称。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.