Case with doctrine2, symfony2, and postgresql objects

I have a problem with doctrine2 in a symfony2 application with a postgres database.

I get an error:

SQLSTATE[3F000]: Invalid schema name: 7 ERROR: schema "main" does not exist 

The problem is that my circuit is not Main. When I rename it, a similar situation holds for a table relation:

 SQLSTATE[42P01]: Undefined table: 7 ERROR: relation "main.brand_brandid_seq" does not exist 

The problem is case sensitivity, and I think this may be due to quoting or some configuration of the doctrine.

Entity:

 namespace MyB\Entity; /** * MyB\Entity\Brand * * @orm:Table(name="Main.Brand") * @orm:Entity */ class Brand { /** * @var integer $brandid * * @orm:Column(name="BrandId", type="integer", nullable=false) * @orm:Id * @orm:GeneratedValue(strategy="SEQUENCE") * @orm:SequenceGenerator(sequenceName="Main.Brand_BrandId_seq", allocationSize="1", initialValue="1") */ private $brandid; /** * @var string $brandname * * @orm:Column(name="BrandName", type="string", length=32, nullable=false) */ private $brandname; /** * Set name. * * @param string $name */ public function setName($name) { $this->brandname = $name; } } 

Scheme:

 SET search_path = "Main", pg_catalog; CREATE SEQUENCE "Brand_BrandId_seq" START WITH 2 INCREMENT BY 1 NO MAXVALUE NO MINVALUE CACHE 1; SET default_tablespace = ''; SET default_with_oids = false; CREATE TABLE "Brand" ( "BrandId" integer DEFAULT nextval('"Brand_BrandId_seq"'::regclass) NOT NULL, "BrandName" character varying(32) NOT NULL ); 

Controller:

  $reseller = new \MyB\Entity\Brand(); $reseller->setName('Sasa'); $em = $this->get('doctrine.orm.entity_manager'); $em->persist($reseller); $em->flush(); 

Any idea?

+4
source share
4 answers

try it

 namespace MyB\Entity; /** * MyB\Entity\Brand * * @orm:Table(name="""Main"".""Brand""") * @orm:Entity */ class Brand { /** * @var integer $brandid * * @orm:Column(name="""BrandId""", type="integer", nullable=false) * @orm:Id * @orm:GeneratedValue(strategy="SEQUENCE") * @orm:SequenceGenerator(sequenceName="""Main"".""Brand_BrandId_seq""", allocationSize="1", initialValue="1") */ private $brandid; /** * @var string $brandname * * @orm:Column(name="""BrandName""", type="string", length=32, nullable=false) */ private $brandname; /** * Set name. * * @param string $name */ public function setName($name) { $this->brandname = $name; } } 

In postgres, every case-sensitive word must be executed.

+4
source

When using escaped table names, take care of this "error": https://github.com/doctrine/doctrine2/pull/615 . Doctrine takes the first character of the table name as aliasprefix and thus uses a quote, crushing all your SQL queries

+1
source

I write PpSqlBundle, but it is not finished yet, but you can try, I think it should work. It can generate a db form in the same way as in symfony. in config.yml you should have:

 doctrine: dbal: default_connection: default connections: default: driver: dbname: host: user: password: driverClass: PgSqlBundle\Doctrine\DBAL\Driver\PDOPgSql\Driver # it important logging: 

and you should use the command

 app/console doctrine:mapping:import Yourbundlename annotation 

https://github.com/mstrzele/PgSqlBundle

0
source

If you are using migration files on Laravel. Edit Schema :: table to Schema :: create. It might help someone.

0
source

Source: https://habr.com/ru/post/1347003/


All Articles