When using bin/console make:entity
on Mysql and then later you switch your application to Postgres and you have a table called user
, which you most likely have when using security component of Symfony.
Then you will receive an error because user
is a reserved word in Postgres!
An exception occurred while executing 'INSERT INTO user (id, email, roles, password, is_verified) VALUES (?, ?, ?, ?, ?)' with params [3, "dev@dev.de", "[]", "your-encrypted-password", 0]:
SQLSTATE[42601]: Syntax error: 7 ERROR: syntax error at or near "user"
LINE 1: INSERT INTO user (id, email, roles, password, is_verified) V...
To fix this you have to escape the table name on your entity, fe. User.php:
@ORM\Table(name="`user`")
(note the backticks inside the quotes!)
If you generate the entity with maker bundle: bin/console make:entity
directly on Postgres the backticks are added automatically.
But not when you switch the DB type. Then you have to add them manually. :)