我昨天尝试了最近发布的生成器,但遇到了一个问题。我能够正确地创建数据库&实体。但当我尝试创建模式时,它就开始显示错误,比如:
php app/console doctrine:schema:create
[Doctrine'Common'Annotations'AnnotationException]
[Semantical Error] The annotation "@Table" in class Acme'BlogBundle'Entity'Post was never imported.
doctrine:schema:create [--dump-sql] [--em[="..."]]
我终于发现了问题,生成的实体有如下注释:
/**
* Acme'BlogBundle'Entity'Post
*
* @Table()
* @Entity
*/
而不是:
/**
* Acme'BlogBundle'Entity'Post
*
* @ORM'Table(name="post")
* @ORM'Entity
*/
我不得不在@table注释中添加表名,并手动将ORM''添加到所有注释中。
现在错误已经改变:
php app/console doctrine:schema:create
ATTENTION: This operation should not be executed in a production environment.
Creating database schema...
[Exception] DateTime::__construct(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'Asia/Calcutta' for 'IST/5.0/no DST' instead.
doctrine:schema:create [--dump-sql] [--em[="..."]]
如何修复时区错误。
我看到了Symfony Interactive Generators视频,该实体默认使用@ORM''生成。只有表名称用于手动添加。为什么我的发行版生成的注释不正确。
这是配置中的PHP问题,设置时区
date_default_timezone_set('America/Los_Angeles');
控制台通常有一个单独的php.ini文件。
运行php -i | grep "Configuration File"
,这将告诉您控制台的ini文件的位置。在该文件中添加或编辑时区:date.timezone = my/timezone
。
或者,您可以将date_default_timezone_set()
添加到app/AppKernel.php的顶部。
在类文件的类之前的顶部向AppKernel.php
添加以下代码。
date_default_timezone_set('America/New_York');
不正确的实体生成是一个错误,请参阅https://github.com/symfony/symfony/issues/1440