我有一个可疑的问题。我有一组现有的带注释的 Doctrine 实体,它们已在 Symfony2/Doctrine2 项目中成功使用。然而,我目前正在将该项目的一些核心功能隔离到它自己的 Web 框架独立库中,但我似乎无法让这些实体正常运行。
目前我主要担心的是 Doctrine CLI 实用程序给我带来的结果好坏参半。
当我执行以下操作时:
bin/doctrine orm:validate-schema
我得到以下输出:
[Mapping] OK - The mapping files are correct.
[Database] OK - The database schema is in sync with the mapping files.
但是当我这样做时:
bin/doctrine orm:info
我明白了:
[Exception]
You do not have any mapped Doctrine ORM entities according to the current configuration. If you have entities or mapping files you should check your mapping configuration for errors.
我现在已经检查了我的配置无数次了。我什至删除了所有实体,并在其中留下了最基本的用户实体,给了我相同的场景。
这些混合结果的来源可能是什么?
事实证明,标准 Doctrine 配置设置 [1] 不适用于我的代码库或我测试过的任何代码库,也许文档已经过时了。在浏览了几个小时的 Interwebs 之后,这是最终使它对我有用的配置:
use Doctrine\ORM\Tools\Setup;
use Doctrine\ORM\EntityManager;
use Doctrine\Common\Annotations\AnnotationReader;
$paths = array( realpath(__DIR__."/../src/My/Entity") );
$isDevMode = TRUE;
// the connection configuration
$dbParams = array(
'driver' => 'pdo_mysql',
'user' => 'myuser',
'password' => 's3cr3t',
'dbname' => 'mydb',
);
$cache = new \Doctrine\Common\Cache\ArrayCache();
$reader = new AnnotationReader();
$driver = new \Doctrine\ORM\Mapping\Driver\AnnotationDriver($reader, $paths);
$config = Setup::createAnnotationMetadataConfiguration($paths, $isDevMode);
$config->setMetadataCacheImpl( $cache );
$config->setQueryCacheImpl( $cache );
$config->setMetadataDriverImpl( $driver );
$entityManager = EntityManager::create($dbParams, $config);
//-- This I had to add to support the Mysql enum type.
$platform = $entityManager->getConnection()->getDatabasePlatform();
$platform->registerDoctrineTypeMapping('enum', 'string');
[1] http://docs.doctrine-project.org/en/latest/tutorials/getting-started.html http://docs.doctrine-project.org/en/latest/tutorials/getting-started.html
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)