symfony 5.1 Bundle migration result in No mapping information to process
Asked Answered
K

1

2

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

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

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

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

The folders are:

src
 |-- Smartlink
        |-- UserBundle/SmartlinkUserBundle.php
               |-- Application
               |-- Domain
               |     |-- Entity/User.php
               |     |-- interfaces/UserRepository.php
               |-- Infrastructure
                     |-- Repository/MysqlUserRepository.php

The configuration is:

// 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

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

And the entity User is

namespace UserBundle\Domain\Entity;

use UserBundle\Infrastructure\Repository\MysqlUserRepository;

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

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?

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

Kukri answered 11/8, 2020 at 22:41 Comment(0)
K
3

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

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.

And now it works.

Kukri answered 13/8, 2020 at 1:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.