Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Symfony 4 make:entity --regenerate fail with: No entities were found in the "App" namespace

from composer.json

{
    "name": "symfony/website-skeleton",
    "type": "project",
    "license": "MIT",
    "description": "A skeleton to start a new Symfony website",
    "require": {
        "php": "^7.1.3",
        "ext-iconv": "*",
        "sensio/framework-extra-bundle": "^5.1",
        "symfony/apache-pack": "^1.0",
        "symfony/asset": "^4.0",
        "symfony/console": "^4.0",
        "symfony/expression-language": "^4.0",
        "symfony/flex": "^1.0",
        "symfony/form": "^4.0",
        "symfony/framework-bundle": "^4.0",
        "symfony/lts": "^4@dev",
        "symfony/monolog-bundle": "^3.1",
        "symfony/orm-pack": "^1.0",
        "symfony/process": "^4.0",
        "symfony/security-bundle": "^4.0",
        "symfony/serializer-pack": "*",
        "symfony/swiftmailer-bundle": "^3.1",
        "symfony/translation": "^4.0",
        "symfony/twig-bundle": "^4.0",
        "symfony/validator": "^4.0",
        "symfony/web-link": "^4.0",
        "symfony/webpack-encore-pack": "*",
        "symfony/yaml": "^4.0"
    },
    "require-dev": {
        "symfony/browser-kit": "^4.0",
        "symfony/css-selector": "^4.0",
        "symfony/debug-pack": "*",
        "symfony/dotenv": "^4.0",
        "symfony/maker-bundle": "^1.5",
        "symfony/phpunit-bridge": "^4.0",
        "symfony/profiler-pack": "*",
        "symfony/web-server-bundle": "^4.0"
    },
    "config": {
        "preferred-install": {
            "*": "dist"
        },
        "sort-packages": true
    },
    "autoload": {
        "psr-4": {
            "App\\": "src/"
        }
    },
    "autoload-dev": {
        "psr-4": {
            "App\\Tests\\": "tests/"
        }
    },
    "replace": {
        "symfony/polyfill-iconv": "*",
        "symfony/polyfill-php71": "*",
        "symfony/polyfill-php70": "*",
        "symfony/polyfill-php56": "*"
    },
    "scripts": {
        "auto-scripts": {
            "cache:clear": "symfony-cmd",
            "assets:install --symlink --relative %PUBLIC_DIR%": "symfony-cmd"
        },
        "post-install-cmd": [
            "@auto-scripts"
        ],
        "post-update-cmd": [
            "@auto-scripts"
        ]
    },
    "conflict": {
        "symfony/symfony": "*"
    },
    "extra": {
        "symfony": {
            "allow-contrib": false
        }
    }
}

from doctrine.yaml:

# /config/packages/doctrine.yaml
doctrine:
    dbal:
        default_connection: training
        connections:
            training:
                dbname:   "training"
                driver:   "pdo_mysql"
                host:     "localhost"
                port:     "3306"
                user:     "userdb"
                password: "XXXXXXXXXX"
                charset:  UTF8
                mapping_types:
                    bit: boolean
    orm:
        auto_generate_proxy_classes: "%kernel.debug%"
        default_entity_manager: training
        entity_managers:
            training:
                connection: training
                auto_mapping: true

the command:

php bin/console doctrine:mapping:import --em=training App\Entity annotation --path=src/Entity

produce into src/Entity the Course.php entity:

<?php

namespace App\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * Course
 *
 * @ORM\Table(name="course", indexes={@ORM\Index(name="id_product_idx_1", columns={"id_product"}), @ORM\Index(name="enabled_idx_1", columns={"enabled"}), @ORM\Index(name="sort_idx_1", columns={"sort"})})
 * @ORM\Entity
 */
class Course
{
    ....

after run into the console:

php bin/console make:entity --regenerate App

this fail with error:

No entities were found in the "App" namespace

same for

php bin/console make:entity --regenerate App\Entity 

if i try

php bin/console make:entity --regenerate App\Entity\Course

the output is

Could not find Doctrine metadata for "App\Entity\Course". Is it mapped as an entity?

what i'm doing wrong?

like image 760
ar099968 Avatar asked Jan 29 '23 00:01

ar099968


1 Answers

In my case it was because I wrote:

php bin/console make:entity --regenerate App\Entity\Course

instead of (notice double back slashes)

php bin/console make:entity --regenerate App\\Entity\\Course

like image 156
Herz3h Avatar answered Jan 30 '23 14:01

Herz3h