Symfony make:entity 注释映射错误
Symfony make:entity annotation mapping error
我想使用 MakerBundle 中的 make:entity 命令在我的 ORO 平台应用程序中创建一个新实体。
我希望它在我的包 Acme\Bundle\TestBundle
中创建一个实体,我使用以下方法在 config_dev.yml
中设置:
maker:
root_namespace: 'Acme\Bundle\TestBundle'
所以我执行
bin/console make:entity Test
哪个returns
! [NOTE] It looks like your app may be using a namespace other than "Acme\Bundle\TestBundle".
!
! To configure this and make your life easier, see:
! https://symfony.com/doc/current/bundles/SymfonyMakerBundle/index.html#configuration
created: src/Acme/Bundle/TestBundle/Entity/Test.php
created: src/Acme/Bundle/TestBundle/Repository/TestRepository.php
[ERROR] Only annotation mapping is supported by make:entity, but the
<info>Acme\Bundle\TestBundle\Entity\Test</info> class uses a different format. If you would like
this command to generate the properties & getter/setter methods, add your mapping configuration, and then
re-run this command with the <info>--regenerate</info> flag.
我再次尝试 运行 命令,成功了。但显然这不是它的工作方式。那么我该如何解决这个映射错误呢?
我开始使用标准的 Symfony 5 项目 Symfony new myapp
。
我在config/packages/dev/maker.yaml
中添加配置文件
maker:
root_namespace: 'App\Core'
要在 src/Core
文件夹中生成实体,出现以下错误:
➜ symfony console make:entity Post
created: src/Core/Entity/Post.php
created: src/Core/Repository/PostRepository.php
[ERROR] Only annotation mapping is supported by make:entity, but the <info>App\Core\Entity\Post</info> class uses
a different format. If you would like this command to generate the properties & getter/setter methods, add your
mapping configuration, and then re-run this command with the <info>--regenerate</info> flag.
为了避免在控制台中显示错误,我安装了 vklux / maker-bundle-force-annotation
创建的补丁
第 1 步:安装包
composer require cweagans/composer-patches
第 2 步:在 composer.json
中应用补丁
{
// {...} composer.json content
"extra": {
"patches": {
"symfony/maker-bundle": {
"Provide flag to force annotation in make entity command": "https://raw.githubusercontent.com/vklux/maker-bundle-force-annotation/master/maker-force-annotation-flag.patch"
}
}
}
}
第 3 步:作曲家更新
composer update
第 4 步:尝试 make:entity
使用附加命令选项
➜ symfony console make:entity Post --force-annotation
created: src/Core/Entity/Post.php
created: src/Core/Repository/PostRepository.php
Entity generated! Now let's add some fields!
You can always add more fields later manually or by re-running this command.
New property name (press <return> to stop adding fields):
>
✅ 现在一切正常。
教义版有bug请试试这个版本祝你好运
composer req doctrine/doctrine-bundle:2.2
我想使用 MakerBundle 中的 make:entity 命令在我的 ORO 平台应用程序中创建一个新实体。
我希望它在我的包 Acme\Bundle\TestBundle
中创建一个实体,我使用以下方法在 config_dev.yml
中设置:
maker:
root_namespace: 'Acme\Bundle\TestBundle'
所以我执行
bin/console make:entity Test
哪个returns
! [NOTE] It looks like your app may be using a namespace other than "Acme\Bundle\TestBundle".
!
! To configure this and make your life easier, see:
! https://symfony.com/doc/current/bundles/SymfonyMakerBundle/index.html#configuration
created: src/Acme/Bundle/TestBundle/Entity/Test.php
created: src/Acme/Bundle/TestBundle/Repository/TestRepository.php
[ERROR] Only annotation mapping is supported by make:entity, but the
<info>Acme\Bundle\TestBundle\Entity\Test</info> class uses a different format. If you would like
this command to generate the properties & getter/setter methods, add your mapping configuration, and then
re-run this command with the <info>--regenerate</info> flag.
我再次尝试 运行 命令,成功了。但显然这不是它的工作方式。那么我该如何解决这个映射错误呢?
我开始使用标准的 Symfony 5 项目 Symfony new myapp
。
我在config/packages/dev/maker.yaml
maker:
root_namespace: 'App\Core'
要在 src/Core
文件夹中生成实体,出现以下错误:
➜ symfony console make:entity Post
created: src/Core/Entity/Post.php
created: src/Core/Repository/PostRepository.php
[ERROR] Only annotation mapping is supported by make:entity, but the <info>App\Core\Entity\Post</info> class uses
a different format. If you would like this command to generate the properties & getter/setter methods, add your
mapping configuration, and then re-run this command with the <info>--regenerate</info> flag.
为了避免在控制台中显示错误,我安装了 vklux / maker-bundle-force-annotation
第 1 步:安装包
composer require cweagans/composer-patches
第 2 步:在 composer.json
中应用补丁
{
// {...} composer.json content
"extra": {
"patches": {
"symfony/maker-bundle": {
"Provide flag to force annotation in make entity command": "https://raw.githubusercontent.com/vklux/maker-bundle-force-annotation/master/maker-force-annotation-flag.patch"
}
}
}
}
第 3 步:作曲家更新
composer update
第 4 步:尝试 make:entity
使用附加命令选项
➜ symfony console make:entity Post --force-annotation
created: src/Core/Entity/Post.php
created: src/Core/Repository/PostRepository.php
Entity generated! Now let's add some fields!
You can always add more fields later manually or by re-running this command.
New property name (press <return> to stop adding fields):
>
✅ 现在一切正常。
教义版有bug请试试这个版本祝你好运
composer req doctrine/doctrine-bundle:2.2