4

我在带有 postgres 数据库的 symfony2 应用程序中的教义2 有问题。

我得到错误:

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

问题是我的架构是主要的而不是主要的。当我重命名它时,表关系发生了类似的事情:

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

问题是区分大小写,我想这可能与引用或某些学说配置有关。

实体:

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

架构:

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

控制器:

        $reseller = new \MyB\Entity\Brand();
        $reseller->setName('Sasa');

        $em = $this->get('doctrine.orm.entity_manager');
        $em->persist($reseller);
        $em->flush();

任何想法?

4

4 回答 4

4

尝试这个

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

在 postgres 中,每个单词都区分大小写必须是转义。

于 2011-04-07T05:56:49.403 回答
1

使用转义表名时,请注意这个“错误”:https ://github.com/doctrine/doctrine2/pull/615 。Doctrine 将表名的第一个字符作为别名前缀,因此使用了引号,从而破坏了所有 SQL

于 2013-12-24T11:13:08.310 回答
0

I write PpSqlBundle but it isn't finished yet, but you could try, I think it should work. It can generate form db same 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's important
            logging:  

and you should use command

app/console doctrine:mapping:import Yourbundlename annotation

https://github.com/mstrzele/PgSqlBundle

于 2011-04-07T06:59:27.093 回答
0

如果你在 Laravel 上使用迁移文件。将 Schema::table 更改为 Schema::create。这可能会帮助某人。

于 2015-12-02T08:56:00.360 回答