I'm trying to add a new boolean property on an entity, but when I execute the doctrine:schema:update command, I get the following error:
[PDOException]
SQLSTATE[42000]: Syntax error or access violation: 1064 Syntax error near
'generated TINYINT(1) DEFAULT '1'' at line 1
Here's my code:
/**
* @var boolean
*
* @ORM\Column(type="boolean", nullable=true, options={"default":true})
*/
private $generated;
I also tried to set default to 0
, to 1
, to false
...
I also tried this:
private $generated = 0
private $generated = false
...
I also tried to set default value via the constructor, but nothing is working.
And finally, I tried without any default values, and got this error:
[PDOException]
SQLSTATE[42000]: Syntax error or access violation: 1064 Syntax error near 'generated TINYINT(1) DEFAULT NULL' at line 1
It seems I'm the only person using Symfony to get this error :( If anyone has any idea... Thanks a lot
Charles
答案 0 :(得分:0)
generated
is a reserved word in mysql, so you have to quote the name according to the documentation:
Sometimes it is necessary to quote a column or table name because of reserved word conflicts. Doctrine does not quote identifiers automatically, because it leads to more problems than it would solve. Quoting tables and column names needs to be done explicitly using ticks in the definition.
after that you can initialize it directly:
/**
* @var boolean
*
* @ORM\Column(name=`generated`, type="boolean", nullable=true)
*/
private $generated = true;
and call your update statement with the force
parameter, like doctrine:schema:update --force
答案 1 :(得分:0)
See the below link for more info
https://dev.mysql.com/doc/refman/5.7/en/keywords.html#ftn.idm140475758235952
'generated is a mysql reserverd keyword since 5.7.6