symfony 5.1软件包迁移导致没有要处理的映射信息 [英] symfony 5.1 Bundle migration result in No mapping information to process

查看:121
本文介绍了symfony 5.1软件包迁移导致没有要处理的映射信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在DDD下开发一个Symfony 5.1项目,所以我要更改所有默认文件夹。

I'm developing a Symfony 5.1 project under DDD, so I'm changing a bit all the default folders.

我在src文件夹中有2个捆绑包,目前我只其中有一个实体。

I have 2 bundles inside src folder and at the moment I only have entities inside one of them.

我使用make:user命令生成了Entity User及其存储库,然后移动了文件并更改了名称空间,路由,配置等

I generated the Entity User and its repository with the command make:user and then moved the files and changed namespaces, routes, configs, etc

当我运行 php bin / console make:migration 时,出现错误没有要处理的映射信息

When I run php bin/console make:migration I get an error "No mapping information to process"

$ 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

The UserRepository is the same that generated the make:user command except for the namespace, which is changed to namespace UserBundle\Infrastructure\Repository; and the name that is changed to MysqlUserRepository that implements the interface UserRepository

,实体User为

namespace UserBundle\Domain\Entity;

use UserBundle\Infrastructure\Repository\MysqlUserRepository;

/**
 * @ORM\Entity(repositoryClass=MysqlUserRepository::class)
 */
class User implements UserInterface
{
    ...

我一直在搜索,发现的只是关于symfony 2和symfony 4,我尝试过对于询问过问题的人而言,效果仍然相同,但仍无法生成捆绑包的迁移。我缺少什么?

I've been searching and all I have found is about symfony 2 and symfony 4, I tried the same that worked for the people who was asking, but still can't generate the migration of the bundles. what am I missing?

编辑:我更改了一些配置,并解决了UserBundle找不到或未激活的问题,但主要的迁移问题仍然存在

I changed some configurations and solved the UserBundle is not found or is not active but the main migration problem remains

推荐答案

最后我找到了答案,解决方法是在文件 config / packages / doctrine.yaml

Finally I found an answer, the solution is in the file 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
dir:是错误的,所以我不得不修复它
,然后添加了前缀,没有前缀就出现了错误。

The fix is setting in_bundle to false the dir: was wrong, so I had to fix it and I added the prefix, without the prefix there was an error.

现在可以正常工作了。

这篇关于symfony 5.1软件包迁移导致没有要处理的映射信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆