如何在 Symfony 中应用 Doctrine 元数据更改
How to apply Doctrine metadata change in Symfony
所以我有一个名为 "Release" 的 MySQL 数据库 table,不幸的是它恰好是一个保留关键字。我运行
php bin/console doctrine:generate:entities AppBundle
现在出现 SQL 错误:
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'release t0 WHERE t0.ReleaseID = 2' at line 1
所以我在classAppBundle\Entity\Release
.
中手动转义了table名字
/**
* Release
*
* @ORM\Table(name="`Release`", indexes={@ORM\Index(name="FK_ProductID_Release", columns={"ProductID"})})
* @ORM\Entity
*/
class Release
我运行
php bin/console doctrine:cache:clear-metadata
但我仍然遇到同样的错误。还有什么可以通知 Doctrine 有关更改?
我发现了问题,它很奇怪。我遵循了 http://symfony.com/doc/current/cookbook/doctrine/reverse_engineering.html 上的指南,并且
使用命令
php bin/console doctrine:mapping:import --force AppBundle xml
生成现有数据库的描述。这在 app/src/AppBundle/Resources/config/doctrine 中创建了文件,这些文件似乎优先于实体中的注释。这应该在文档中提到。
更新
具体这部分
php bin/console doctrine:mapping:convert annotation ./src
文档中的应该改为
php bin/console doctrine:mapping:convert xml ./src
所以我有一个名为 "Release" 的 MySQL 数据库 table,不幸的是它恰好是一个保留关键字。我运行
php bin/console doctrine:generate:entities AppBundle
现在出现 SQL 错误:
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'release t0 WHERE t0.ReleaseID = 2' at line 1
所以我在classAppBundle\Entity\Release
.
/**
* Release
*
* @ORM\Table(name="`Release`", indexes={@ORM\Index(name="FK_ProductID_Release", columns={"ProductID"})})
* @ORM\Entity
*/
class Release
我运行
php bin/console doctrine:cache:clear-metadata
但我仍然遇到同样的错误。还有什么可以通知 Doctrine 有关更改?
我发现了问题,它很奇怪。我遵循了 http://symfony.com/doc/current/cookbook/doctrine/reverse_engineering.html 上的指南,并且 使用命令
php bin/console doctrine:mapping:import --force AppBundle xml
生成现有数据库的描述。这在 app/src/AppBundle/Resources/config/doctrine 中创建了文件,这些文件似乎优先于实体中的注释。这应该在文档中提到。
更新 具体这部分
php bin/console doctrine:mapping:convert annotation ./src
文档中的应该改为
php bin/console doctrine:mapping:convert xml ./src