开发者

Doctrine and Postgresql, Generate Models from DB Problem

I have a database in Postgresql 9.0 and I'm trying to use Doctrine ORM 1.2 to generate models from db.

Here is my code:

<?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));
?>

and when I run the page, I get this error:

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

It's worth to mention, this code is working perfectly for mysql (by having mysql:// ... in the connect开发者_如何学Pythonion ofcurse), but having trouble to get it working with postgresql 9.0.

Any idea?


Sounds like this bug in Doctrine: http://www.doctrine-project.org/jira/browse/DC-919


Try to add quotes to table name, or column names.

Find right naming while exporting a table.

My problem was that someone added quotes to table name.

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜