MySQL错误1064,单列表

huangapple go评论77阅读模式
英文:

MySQL Error 1064 with single Column Table

问题

我正在使用Laravel/Homestead进行开发,并将MySQL作为我的数据库。出于测试目的,我尝试插入数据以测试我的关系(是的,你可以使用seeders来实现这一点,但对于我的数据库规模来说,编写seeders太复杂了)。

我所有的插入操作都成功了,除了一个。当我尝试插入到表'Character'时,会抛出错误1064 (42000)。这个表只有两列:characterId和name(字符串)。

详细的异常消息是:

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 'Character(name) VALUES("Random name")' at line 1

我的插入语句如下:INSERT INTO Character(`name`) VALUES("James Brafferson");

我已经尝试将列名更改为characterName,但也没有成功。有谁知道问题出在哪里吗?

英文:

I am developing with Laravel/Homestead and I use MySQL as my database. For test purposes, I tried to insert data to test my relationships (yes, you can use seeders for this, but it was too complex writing it for the scale of my database).

All of my Inserts worked, except for one. The Table 'Character' throws an error 1064 (42000), when I try to insert. This table has only two columns: a characterId and a name (String).

The detailed exception message is:

> 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 'Character(name) VALUES("Random name")' at line 1

My insert looks like this: INSERT INTO Character(`name`) VALUES("James Brafferson");

I already tried to rename the column name to characterName, that didn't work either. Does anyone know what's wrong?

答案1

得分: 3

"Character" 是 MySQL 中的 保留字。您可以添加 ` 符号来进行转义。

请尝试以下查询:

INSERT INTO `Character` (`name`) VALUES ("James Brafferson");

或者您可以重新命名表名,该表名不在 关键字或保留字列表 中。

英文:

Character is a reserved word in MySQL. You can add the ` symbol to escape it.

Can you please try the below query:

INSERT INTO `Character` (`name`) VALUES ("James Brafferson");

or you may rename the table name, which is not in the keyword or reserved word list.

huangapple
  • 本文由 发表于 2020年1月6日 02:29:06
  • 转载请务必保留本文链接:https://go.coder-hub.com/59602964.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定