Kurtis with his dog Guinness (Australian Shepherd)
CTO @ Fullscript. Focused on building great teams, culture, and software.

September 2012

Doctrine Entity Table Names & Linux

As I was glancing over a past article I’d written, [Mapping Entities in Symfony2][mapping-entities], I noticed that I had only briefly mentioned the Doctrine @Table(name="your-table-name") annotation. [mapping-entities]: /2011/12/mapping-entities-in-symfony2.html

Many of you who use the Symfony console commands to quickly create your Entities will notice that the @Table(name="") is not included by default on Entities. Just recently I was starting a new application with ~20 Entities to generate. Using the entity generator (seen below) was a huge time-saver, begin by typing the following into terminal.

php app/console doctrine:generate:entity --entity="kurtfunaiExampleBundle:MyEntityName"

I primarily develop on a Mac where case sensitivity in MySQL is non-existant. The tablenames in my schema are all lower case, and separated by underscores (ex: user, user_type).

I launched the app on our staging server (running Ubuntu). Immediately the exceptions started popping up:

SQLSTATE[42S02]: Base table or view not found: 1146 Table 'my_database.User' doesn't exist

It is a minor issue, and luckily very easy to fix!… Declare your table names in your entities!

/**
 * kurtfunai\ExampleBundle\Entity\User
 *
 * @ORM\Table()
 * @ORM\Entity
 * @ORM\Table(name="user")
 */
class User
{

That’s it, your table-name issues will be solved!

© Kurtis Funai 2021