Doctrine和Postgresql,从DB问题生成模型

时间:2010-11-21 05:11:56

标签: postgresql doctrine doctrine-1.2

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

这是我的代码:

<?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:// ...连接ofcurse),但是无法使用postgresql 9.0。

有什么想法吗?

2 个答案:

答案 0 :(得分:1)

听起来像Doctrine中的这个错误:http://www.doctrine-project.org/jira/browse/DC-919

答案 1 :(得分:0)

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

在导出表格时找到正确的命名。

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

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