如何在Doctrine映射中为表设置PostgreSQL模式?

8

我有两个Symfony应用程序映射到同一个PgSQL数据库。这两个应用程序都使用FOSUserBundle,因此我正在尝试在不同的模式下处理用户。通过阅读和进行一些谷歌研究,我按照以下方式构建了我的实体:

/**
 * @ORM\Entity
 * @ORM\Table(name="internal_users", schema="internal")
 * @Gedmo\SoftDeleteable(fieldName="deletedAt", timeAware=false)
 */
class InternalUser extends BaseUser
{
    ...
}

接下来我尝试在Symfony2的shell中输入以下命令:

Symfony > doctrine:schema:validate
[Mapping]  OK - The mapping files are correct.
[Database] FAIL - The database schema is not in sync with the current mapping file.
The command terminated with an error status (2)
Symfony > doctrine:schema:update --force
Updating database schema...
Database schema updated successfully! "14" queries were executed
Symfony >

但是表格生成在public模式下,而不是我想要的internal模式下,我做错了什么?有没有办法在不同的模式下创建表格?


1
尝试使用@ORM\Table(name="internal.internal_users") - Salem
@Salem,可以了,请将您的评论发布为答案以获得积分。 - ReynierPM
2个回答

8

作为一种解决方法,您可以使用SCHEMA.TABLE作为表名:

@ORM\Table(name="internal.internal_users")

7
自Doctrine ORM 2.5版本起,您可以使用“schema”属性(参见参考文献):
@ORM\Table(schema="internal")

或者在YAML驱动程序中使用 schema 选项:

App\Entity\InternalUser:
  table: internal_users
  schema: internal

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接