Doctrine Entity and MySQL Reserved Words


Recently for an app I’ve been creating I had to create a ExitForm Doctrine Entity. So I simply created the following code:


// src/AppBundle/Entity/ExitForm.php
namespace AppBundle\Entity;

use Doctrine\ORM\Mapping as ORM;

* @ORM\Entity
* @ORM\Table(name="exit")
class ExitForm

Then after that I ran the standard Symfony commands to generate getters/setters and update the database:

php bin/console doctrine:generate:entities AppBundle/Entity/ExitForm
php bin/console doctrine:schema:update --force

Everything looks fine an ran without any errors

Checking on the MySQL Database

Then, I went into MySQL and ran the following commands:

show tables;

It showed all my tables, and it showed “exit” as one of the tables. Then I ran this command:

describe exit;

It gave me errors. I struggled for a awhile trying to figure out what the problem was, but then I figured it out, “exit” is a MySQL Reserved Word. So instead of using that I changed my code to this:

* @ORM\Entity
* @ORM\Table(name="exitform")
class ExitForm

Everything worked correctly after that. This is just a lesson never to use a Reserved Word.



About Alvin Bunk
Hi, I'm a software developer at Taft College.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: