本文介绍了案例与doctrine2,symfony2和postgresql实体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我收到错误:
<$ p
我在symfony2应用程序中有一个postgres数据库的doctrine2问题$ p> SQLSTATE [3F000]:模式名称无效:7错误:模式main不存在
问题是我的模式是Main不是main。当我重命名时,类似的事情发生在表关系中:
SQLSTATE [42P01]:未定义的表:7 ERROR:relationmain .brand_brandid_seq不存在
问题是区分大小写,我猜也许这与引用有关或一些教义配置。
实体:
命名空间MyB\实体;
/ **
* MyB\Entity\Brand
*
* @orm:Table(name =Main.Brand)
* @orm:Entity
* /
class品牌
{
/ **
* @var整数$ brandid
*
* orm:Column(name =BrandId,type =integer,nullable = false)
* @orm:Id
* @orm:GeneratedValue(strategy =SEQUENCE)
* @orm:SequenceGenerator(sequenceName =Main.Brand_BrandId_seq,allocateSize =1,initialValue =1)
* /
private $ brandid;
/ **
* @var string $ brandname
*
* @orm:列(name =BrandName,type =string,length = 32,nullable = false)
* /
private $ brandname;
/ **
*设置名称。
*
* @param string $ name
* /
public function setName($ name){
$ this-> brandname = $ name;
}
}
模式:
SET search_path =Main,pg_catalog;
CREATE SEQUENCEBrand_BrandId_seq
START WITH 2
增加1
无MAXVALUE
无MINVALUE
CACHE 1;
SET default_tablespace ='';
SET default_with_oids = false;
CREATE TABLE品牌(
BrandIdinteger DEFAULT nextval('Brand_BrandId_seq':: regclass)NOT NULL,
BrandName (32)NOT NULL
);
控制器:
code> $ reseller = new \MyB\Entity\Brand();
$ reseller-> setName('Sasa');
$ em = $ this-> get('doctrine.orm.entity_manager');
$ em-> persist($ reseller);
$ em-> flush();
任何想法?
解决方案
尝试这个
命名空间MyB\Entity;
/ **
* MyB\Entity\Brand
*
* @orm:Table(name =Main。 )
* @orm:Entity
* /
class品牌
{
/ **
* @var整数$ brandid
*
* @orm:列(name =BrandId,type =integer,nullable = false)
* @orm:Id
* @orm:GeneratedValue (strategy =SEQUENCE)
* @orm:SequenceGenerator(sequenceName =Main。Brand_BrandId_seq,allocateSize =1,initialValue =1)
* /
private $ brandid;
/ **
* @var string $ brandname
*
* @orm:列(name =BrandName,type =string ,length = 32,nullable = false)
* /
private $ brandname;
/ **
*设置名称。
*
* @param string $ name
* /
public function setName($ name){
$ this-> brandname = $ name;
}
}
在postgres中,每个区分大小写的字都必须转义。 / p>
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?
解决方案
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.
这篇关于案例与doctrine2,symfony2和postgresql实体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!