Dani California
Dani California

Reputation: 331

Symfony: Doctrine cannnot find table with first letter Uppercase

I have this database in which all tables have this format:

Somedata

and the names of the columns are like this:

UserInformation

Basically, the first letter is capitalized, and Doctrine cannot find the table/column

I tried adding a naming strategy:

naming_strategy: doctrine.orm.naming_strategy.underscore

But that didn't work.

I also tried to set MySQL lower case table names to 1

lower_case_table_names = 1

That didn't work as well. If I change all the names of the tables and columns to lowercase, works as expected. However, I cannot do that in the production database, so how can make Doctrine find the tables with that format?

By the way, the tables are already created, and I cannot modify them

Upvotes: 1

Views: 1981

Answers (3)

Elikill58
Elikill58

Reputation: 4908

For Symfony 6, you should use #[ORM\Table("Somename")]. It should be used like that:

#[ORM\Entity(repositoryClass: SomenameRepository::class)]
#[ORM\Table("Somename")]
class Somename {
   // here all your fields
}

Upvotes: 0

Dani California
Dani California

Reputation: 331

UPDATE:

Found the solution. I had to write the table name in the Entity like this:

@ORM\Table(name="`Somename`")

Source:

Doctrine - PostgreSQL - Uppercase and Spaces in Table / Field names

Upvotes: 1

Vadim Ashikhman
Vadim Ashikhman

Reputation: 10136

You have 2 choices here:

  1. Implement custom naming strategy where you generate table names as you wish. Check the docs Doctrine Naming Strategy
  2. Set desired table name in every entity: @ORM\Table(name="SomeName")

Upvotes: 1

Related Questions