具有doctrine2、symfony2 和 postgresql 实体的案例
我在使用 postgres 数据库的 symfony2 应用程序中遇到了关于 Dodocy2 的问题。
我收到错误:
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
);
控制器:
$reseller = new \MyB\Entity\Brand();
$reseller->setName('Sasa');
$em = $this->get('doctrine.orm.entity_manager');
$em->persist($reseller);
$em->flush();
有什么想法吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
试试这个
在 postgres 中,每个区分大小写的单词都必须转义。
Try this
In postgres every word case sensitive must be escape.
使用转义表名称时请注意此“错误”: https://github.com/doctrine/学说2/pull/615 。 Doctrine 将表名的第一个字符作为别名前缀,因此使用了引号,从而粉碎了所有 SQL
When using escaped table names take care about this "bug" : https://github.com/doctrine/doctrine2/pull/615 . Doctrine takes the first character of the table name as aliasprefix and thus a quote is used, crushing all your SQLs
我写了 PpSqlBundle 但还没有完成,但你可以尝试一下,我认为它应该可以工作。
它可以生成与 symfony 中相同的表单数据库。在 config.yml 中你应该有:
并且你应该使用命令
https://github.com/mstrzele/PgSqlBundle
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:
and you should use command
https://github.com/mstrzele/PgSqlBundle
如果您在 Laravel 上使用迁移文件。将 Schema::table 更改为 Schema::create。这可能会对某人有所帮助。
If you are using migration files on Laravel. Change Schema::table to Schema::create. This might help someone.