代码之家  ›  专栏  ›  技术社区  ›  Pooria

Doctrine和Postgresql,从数据库问题生成模型

  •  1
  • Pooria  · 技术社区  · 14 年前

    我在Postgresql 9.0中有一个数据库,我试图使用Doctrine ORM 1.2从数据库生成模型。

    这是我的代码:

    <?php
    require_once 'Doctrine.php';
    spl_autoload_register(array('Doctrine', 'autoload'));
    spl_autoload_register(array('Doctrine_Core', 'modelsAutoload'));
    $manager = Doctrine_Manager::getInstance(); 
    $conn = Doctrine_Manager::connection('pgsql://postgres:secret@192.168.1.108/erp','doctrine');
    $conn->setAttribute( Doctrine_Core::ATTR_PORTABILITY, Doctrine_Core::PORTABILITY_FIX_CASE | PORTABILITY_RTM);
    $conn->setAttribute( Doctrine_Core::ATTR_QUOTE_IDENTIFIER, true);
    $manager->setAttribute(Doctrine_Core::ATTR_AUTO_ACCESSOR_OVERRIDE, true);
    Doctrine_Core::loadModels('../application/models');
    Doctrine_Core::generateModelsFromDb('../application/models', array('doctrine'), array('generateTableClasses' => true));
    ?>
    

    当我运行页面时,会出现以下错误:

    Fatal error: Uncaught exception 'Doctrine_Connection_Pgsql_Exception' with message 'SQLSTATE[42P01]: Undefined table: 7 ERROR: missing FROM-clause entry for table "t" LINE 6: ... t.typtype ... ^. Failing Query: "SELECT ordinal_position as attnum, column_name as field, udt_name as type, data_type as complete_type, t.typtype AS typtype, is_nullable as isnotnull, column_default as default, ( SELECT 't' in D:\Doctrine-1.2.3\Doctrine-1.2.3\Doctrine\Connection.php on line 1082
    

    值得一提的是,这段代码非常适合mysql(通过使用mysql://。。。当然是这样),但在使用postgresql 9.0时遇到问题。

    知道吗?

    2 回复  |  直到 14 年前
        1
  •  1
  •   Frank Heikens    14 年前

    听起来像是教义上的错误: http://www.doctrine-project.org/jira/browse/DC-919

        2
  •  0
  •   Andro Selva Anand Wadhwani    12 年前

    尝试在表名或列名中添加引号。

    导出表时查找正确的命名。

    我的问题是有人给表名加了引号。

    $sql='SELECT "id","name",
       ("f1"=\'aaa\' OR
       "f1"=\'bbb\') AS "myflag"
       FROM "mytable"';