Doctrine 和 Postgresql,从数据库问题生成模型
我有一个 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:[email protected]/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 来说工作得非常完美(通过在curse连接中使用 mysql:// ... ),但是很难获取它与 postgresql 9.0 一起使用。
有什么想法吗?
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:[email protected]/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 connection ofcurse), but having trouble to get it working with postgresql 9.0.
Any idea?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
听起来像 Doctrine 中的这个错误: http://www.doctrine-project.org/ jira/浏览/DC-919
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.