A
A
Alexey Vinogradov2020-11-17 14:04:28
symfony
Alexey Vinogradov, 2020-11-17 14:04:28

How to fix migration error Error Unknown Entity namespace alias 'App\Common'?

Hello everyone, I'm asking for help when I try to perform a migration, I get an error:

Migrating up to 20202610164832 from 20190703153532
  ++ migrating 20202610164832
Migration 20202610164832 failed during Execution. Error Unknown Entity namespace alias 'App\Common'.


Doctrine config is:
doctrine.yanl

parameters:
    # Adds a fallback DATABASE_URL if the env var is not set.
    # This allows you to run cache:warmup even if your
    # environment variables are not available yet.
    # You should not need to change this value.
#    env(DATABASE_URL): 'pgsql://%dbuser%:%dbpass%@%dbhost%:%dbport%/%dbname%'
    # 'mysql://db_user:[email protected]:3306/db_name'

doctrine:
    dbal:
#      charset: utf8mb4
        default_connection: oracle_db
        connections:
           #Postgresql
#           pgsql:
#                driver:   pdo_pgsql
#                host:     "%dbhost%"
#                port:     "%dbport%"
#                dbname:   "%dbname%"
#                user:     "%dbuser%"
#                password: "%dbpass%"
#                charset:  UTF8
            oracle_db:
                driver:    'oci8' # ... or 'pdo_oci'
                dbname:    '%dbname%'
                host:      '%dbhost%'
                port:      '%dbport%'
                user:      '%dbuser%'
                password:  '%dbpass%'
                charset:   'utf8'
#                default_table_options:
#                    collate: 'utf8mb4_unicode_ci'
            customer:
                driver:     'pdo_sqlsrv'
                dbname:     '%msdbname%'
                host:       '%msdbhost%'
                port:       '%msdbport%'
                user:       '%msdbuser%'
                password:   '%msdbpass%'
                charset:    'utf-8'

    orm:
        auto_generate_proxy_classes: "%kernel.debug%"
        default_entity_manager: oracle_db
        entity_managers:
            oracle_db:
                connection: oracle_db
                naming_strategy: doctrine.orm.naming_strategy.underscore
                auto_mapping: true
                mappings:
                    App:
                        is_bundle: false
                        type: annotation
                        dir: '%kernel.project_dir%/src/Common/Entity'
                        prefix: 'App\Common\Entity'
                        alias: App\Common

                    OracleDB:
                        is_bundle: false
                        type: annotation
                        dir: '%kernel.project_dir%/src/OracleDB/Entity'
                        prefix: 'App\OracleDB\Entity'
                        alias: App\OracleDB

                    Cecs:
                        is_bundle: false
                        type: annotation
                        dir: '%kernel.project_dir%/src/Cecs/Entity'
                        prefix: 'App\Cecs\Entity'
                        alias: App\Cecs
            mssql:
                connection: customer
                mappings:
                    Mssql:
                        is_bundle: false
                        type: annotation
                        dir: '%kernel.project_dir%/src/Entity'
                        prefix: 'App\Mssql\Entity'
                        alias: App\Mssql



The migration itself:

spoiler

<?php declare(strict_types=1);

namespace App\Common\Migrations;

use App\Common\Entity\SystemRole;
use Doctrine\Migrations\AbstractMigration;
use Doctrine\DBAL\Schema\Schema;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
 * Страницы тестирования - устанавливаем права на 1 страницу,
 * имея в виду, что это будут права для целого раздела тестирование
 * установка прав только для суперадминистраторов
 */
class Version20202610164832 extends AbstractMigration implements ContainerAwareInterface
{
    private $container;

    public function setContainer(ContainerInterface $container = null)
    {
        $this->container = $container;
    }

    public function up(Schema $schema): void
    {
        $em = $this->container->get("doctrine")->getManager();
        $sysRoleGroup = $em->getRepository("App\Common:SystemRole")->find(1);
        $old_permissions = $sysRoleGroup->getRulesArray();

        $new_permissions = array(
            'page_vm' =>
                array(
                    'path' => 'VmController::vmList',
                    'route' => '/page/vm',
                    'id' => 1259,
                    'parent_id' => 0,
                    'name_rule' => 'oracle_vm',
                    'display_name' => 'Виртуальные машины',
                    'action_rule' =>
                        array(
                            0 => 'read',
                            1 => 'write',
                            3 => 'delete',
                            4 => 'update',
                            5 => 'exec',
                        ),
                ),
        );

        unset($old_permissions['page_vm']);

        $permissions_str = json_encode(array_merge($old_permissions, $new_permissions));

        $sysRoleGroup->setRules($permissions_str);
        $em->persist($sysRoleGroup);
        $em->flush();

        //Устанавливаем права для админов
        $new_admin_perm = [
            'oracle_vm' =>
                array(
                    'read' => true,
                    'write' => true,
                    'delete' => true,
                    'update' => true,
                    'exec' => true,
                )
        ];

//        //Выставляем права для суперадминов
//        //--------------------------------------------------------------------------------------------------------------
//        $admin_rg = $this->connection->executeQuery("SELECT rules FROM cdms.role_group WHERE id = 2")->fetch(2);
//        $admin_current = [];
//        if (!empty($admin_rg['RULES'])) {
//            $admin_current = json_decode($admin_rg['RULES'], true);
//        }
//        //Удаляем права на всякий случай
//        unset($admin_current["oracle_vm"]);
//
//        //Добавляем к существующим разрешением новое
//        $admin_rule_str = json_encode($admin_current + $new_admin_perm);
//
//        //Устанавливаем права только для суперадминистраторов
//        $this->addSql("UPDATE cdms.role_group SET rules ='$admin_rule_str' WHERE id = 2");

    }

    public function down(Schema $schema): void
    {
        //Удаляем правило
        $em = $this->container->get("doctrine")->getManager();
        $sysRoleGroup = $em->getRepository("App\Common:SystemRole")->find(1);
        $old_permissions = $sysRoleGroup->getRulesArray();

        unset($old_permissions['page_vm']);

        $permissions_str = json_encode($old_permissions);

        $sysRoleGroup->setRules($permissions_str);
        $em->persist($sysRoleGroup);
        $em->flush();

        //Откатываем права админов
        //--------------------------------------------------------------------------------------------------------------
        $admin_rg = $this->connection->executeQuery("SELECT rules FROM cdms.role_group WHERE id = 2")->fetch(2);

        $admin_current = json_decode($admin_rg['RULES'], true);

        //Удаляем права
        unset($admin_current["oracle_vm"]);

        //Добавляем к существующим разрешением новое
        $admin_rule_str = json_encode($admin_current);

        //Обновляем права администраторов
        $this->addSql("UPDATE cdms.role_group SET rules ='$admin_rule_str' WHERE id = 2");
    }
}



The most interesting thing is that this migration works on windows, but on linux I get the error that I indicated above

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question