Case with doctrine2, symfony2 and postgresql entities

umpirsky picture umpirsky · Apr 7, 2011 · Viewed 7.3k times · Source

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

I get error:

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

Problem is that my schema is Main not main. When I rename it, similar thing happends for table relation:

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

Problem is case sensitivity and I guess maybe it have something to do with quoting or some doctrine configuration.

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;
    }
}

Schema:

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?

Answer

mstrzele picture mstrzele · Apr 7, 2011

Try this

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 word case sensitive must be escape.