我有一个包含多个模式的PG数据库。
我有一个symfony2应用程序,只需要连接到其中一个。
如果我没有配置任何东西,默认情况下Doctrine2会搜索所有模式,因此它会尝试在表上设置SELECT,而不是在正确的地方。
我的答案是:symfony2 + doctrine2@postgresql setting a schema
现在它似乎只出现在我指定的shema中,但是它仍然在寻找一些在我的模式中不存在的表,而在其他的表中。
当我执行ldoctrine:migrations:diff时

[Doctrine\DBAL\DBALException]
  An exception occurred while executing 'SELECT min_value, increment_by FROM "pgstatspacknameid"':
  SQLSTATE[42P01]: Undefined table: 7 ERROR:  relation "pgstatspacknameid" does not exist
  LINE 1: SELECT min_value, increment_by FROM "pgstatspacknameid"
                                              ^

  [PDOException]
  SQLSTATE[42P01]: Undefined table: 7 ERROR:  relation "pgstatspacknameid" does not exist
  LINE 1: SELECT min_value, increment_by FROM "pgstatspacknameid"
                                              ^

因此,根据条令迁移文档,我在连接配置中添加了这一行:
        schema_filter: ~^(?!pgstats)~

它仍然总是试图在那些表中设置SELECT。。。

最佳答案

您需要migrate命令的选项--db configuration。
它接受一个配置文件作为参数。
请尝试使用配置文件的以下内容。

<?php
return array(
    "driverClass"=>"AppBundle\Driver",
    "host" => "localhost",
    "user" => "test",
    "password" => "test",
    "dbname" => "test"
        );
?>

此外,我还更改了vendor/document/dbal/lib/document/dbal/schemapostgresqlschemanager.php,使其始终将模式前置到序列名。
这样地:
/**
 * {@inheritdoc}
 */
protected function _getPortableSequencesList($sequences)
{
    $sequenceDefinitions = array();
    foreach ($sequences as $sequence) {//+ || true
        if ($sequence['schemaname'] != 'public' || true) {
            $sequenceName = $sequence['schemaname'] . "." . $sequence['relname'];
        } else {
            $sequenceName = $sequence['relname'];
        }

        $sequenceDefinitions[$sequenceName] = $sequence;
    }
    $list = array();

    foreach ($this->filterAssetNames(array_keys($sequenceDefinitions)) as $sequenceName) {
        $list[] = $this->_getPortableSequenceDefinition($sequenceDefinitions[$sequenceName]);
    }
    return $list;
}

/**
 * {@inheritdoc}
 */
protected function getPortableNamespaceDefinition(array $namespace)
{
    return $namespace['nspname'];
}

/**
 * {@inheritdoc}
 */
protected function _getPortableSequenceDefinition($sequence)
{//+ || true
    if ($sequence['schemaname'] != 'public' || true) {
        $sequenceName = $sequence['schemaname'] . "." . $sequence['relname'];
    } else {
        $sequenceName = $sequence['relname'];
    }

    $data = $this->_conn->fetchAll('SELECT min_value, increment_by FROM ' . $this->_platform->quoteIdentifier($sequenceName));

    return new Sequence($sequenceName, $data[0]['increment_by'], $data[0]['min_value']);
}

(在假定架构名称的两个位置添加或true!='公共')

08-18 17:15