我正在 DDD 下开发 Symfony 5.1 项目,因此我对所有默认文件夹进行了一些更改。
我在 src 文件夹中有 2 个包,目前我只在其中一个包中有实体。
我使用命令 make: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 information 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 未找到或不活动的问题,但主要的迁移问题仍然存在