【问题标题】:Doctrine and Postgresql, Generate Models from DB ProblemDoctrine 和 Postgresql,从 DB 问题生成模型
【发布时间】:2010-11-21 05:11:55
【问题描述】:

我在 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(通过在连接 ofcurse 中使用 mysql:// ...),但在使用 postgresql 9.0 时遇到了麻烦。

有什么想法吗?

【问题讨论】:

    标签: postgresql doctrine doctrine-1.2


    【解决方案1】:

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

    【讨论】:

    • 是的,源文件中有错字!!!我很惊讶我已经从 SVN 下载了源代码,但那里仍然存在错字!我已经删除了自己!但是还是谢谢
    【解决方案2】:

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

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

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

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

    【讨论】:

      猜你喜欢
      • 2011-08-19
      • 2015-03-06
      • 1970-01-01
      • 2011-04-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-04-11
      • 2014-09-02
      相关资源
      最近更新 更多