gpt4 book ai didi

postgresql - 带有 doctrine2、symfony2 和 postgresql 实体的案例

转载 作者:行者123 更新时间:2023-11-29 11:33:55 27 4
gpt4 key购买 nike

我在带有 postgres 数据库的 symfony2 应用程序中遇到 doctrine2 问题。

我得到错误:

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

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

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

Controller :

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

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

有什么想法吗?

最佳答案

试试这个

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 中,每个区分大小写的单词都必须进行转义。

关于postgresql - 带有 doctrine2、symfony2 和 postgresql 实体的案例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5573865/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com