问题描述
我正在DDD下开发一个Symfony 5.1项目,所以我要更改所有默认文件夹。
我使用make:user命令生成了Entity User及其存储库,然后移动了文件并更改了名称空间,路由,配置等
运行PHP bin/console make:migration
时出现错误“无映射信息要处理”
$ run PHP bin/console make:migration -v
In NoMappingFound.PHP line 13:
[Doctrine\Migrations\Provider\Exception\NoMappingFound]
No mapping @R_254_4045@ion to process
文件夹为:
src
|-- Smartlink
|-- UserBundle/SmartlinkUserBundle.PHP
|-- Application
|-- Domain
| |-- Entity/User.PHP
| |-- interfaces/UserRepository.PHP
|-- Infrastructure
|-- Repository/MysqLUserRepository.PHP
配置为:
// composer.json
"autoload": {
"psr-4": {
"UserBundle\\": "src/Smartlink/UserBundle","SmartlinkBundle\\": "src/Smartlink/SmartlinkBundle","App\\": "src/"
}
},
================================================
// config/bundles.PHP
return [
...
UserBundle\SmartlinkUserBundle::class => ['all' => true],SmartlinkBundle\SmartlinkSmartlinkBundle::class => ['all' => true],];
================================================
// config/services.yaml
services:
_defaults:
autowire: true # Automatically injects dependencies in your services.
autoconfigure: true # Automatically registers your services as commands,event subscribers,etc.
UserBundle\:
resource: '../src/Smartlink/UserBundle/'
exclude:
- '../src/Smartlink/UserBundle/Domain/Entity/'
SmartlinkBundle\:
resource: '../src/Smartlink/SmartlinkBundle/'
exclude:
- '../src/Smartlink/SmartlinkBundle/Domain/Entity/'
App\:
resource: '../src/'
exclude:
- '../src/DependencyInjection/'
- '../src/Entity/'
- '../src/Kernel.PHP'
- '../src/Tests/'
- '../src/Smartlink/'
================================================
// config/routes/annotations.yaml
userbundle_controllers:
resource: ../../src/Smartlink/UserBundle/Infrastructure/Controller
type: annotation
smartlinkbundle_controllers:
resource: ../../src/Smartlink/SmartlinkBundle/Infrastructure/Controller
type: annotation
controllers:
resource: ../../src/Controller/
type: annotation
kernel:
resource: ../../src/Kernel.PHP
type: annotation
================================================
// config/packages/doctrine.yaml
mappings:
App:
is_bundle: false
type: annotation
dir: '%kernel.project_dir%/src/Entity'
prefix: 'App\Entity'
alias: App
SmartlinkUserBundle:
is_bundle: true
type: annotation
dir: 'Domain/Entity'
alias: user_bundle
SmartlinkSmartlinkBundle:
is_bundle: true
type: annotation
dir: 'Domain/Entity'
alias: smartlink_bundle
UserRepository与生成make:user命令相同,只是名称空间更改为namespace UserBundle\Infrastructure\Repository;
,名称更改为实现接口UserRepository的MysqLUserRepository
实体User是
namespace UserBundle\Domain\Entity;
use UserBundle\Infrastructure\Repository\MysqLUserRepository;
/**
* @ORM\Entity(repositoryClass=MysqLUserRepository::class)
*/
class User implements UserInterface
{
...
我一直在搜索,发现的所有内容都是关于symfony 2和symfony 4的,我尝试过为那些正在问的人使用的工具,但是仍然无法产生捆绑软件的迁移。我想念什么?
编辑:我更改了一些配置并解决了UserBundle找不到或未激活但主要的迁移问题仍然存在的情况
解决方法
最后我找到了答案,解决方法在文件config/packages/doctrine.yaml
mappings:
App:
is_bundle: false
type: annotation
dir: '%kernel.project_dir%/src/Entity'
prefix: 'App\Entity'
alias: App
SmartlinkUserBundle:
is_bundle: false
type: annotation
dir: '%kernel.project_dir%/src/Smartlink/UserBundle/Domain/Entity' # 'Domain/Entity'
prefix: 'UserBundle\Domain\Entity'
alias: UserBundle
SmartlinkSmartlinkBundle:
is_bundle: false
type: annotation
dir: '%kernel.project_dir%/src/Smartlink/SmartlinkBundle/Domain/Entity'
prefix: 'SmartlinkBundle\Domain\Entity'
alias: SmartlinkBundle
此修复程序将in_bundle设置为false 目录:错误,所以我必须修复它 我添加了前缀,但没有前缀就出现了错误。
现在它可以工作了。