![](/img/trans.png)
[英]make:entity command: [ERROR] Only annotation mapping is supported by 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
返回
! [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 new myapp
開始了標准的 Symfony 5 項目。
我在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
創建的補丁
composer require cweagans/composer-patches
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"
}
}
}
}
composer update
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):
>
✅ 🚀 👍 現在一切正常。
這是教義版本中的一個錯誤,請試試這個版本祝你好運
composer req doctrine/doctrine-bundle:2.2
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.