Home > Software engineering >  Symfony 5 - Only attribute mapping is supported by make:entity
Symfony 5 - Only attribute mapping is supported by make:entity

Time:07-28

I have this issue since today and i don't know what caused it. Can't seem to find anyone with this issue neither :/

My composer json

"type": "project",
"license": "proprietary",
"minimum-stability": "stable",
"prefer-stable": true,
"require": {
    "php": ">=8.0",
    "ext-ctype": "*",
    "ext-iconv": "*",
    "aws/aws-sdk-php": "^3.209",
    "aws/aws-sdk-php-symfony": "^2.2",
    "beberlei/doctrineextensions": "^1.3",
    "composer/package-versions-deprecated": "~1.11.99.4",
    "doctrine/annotations": "^1.13",
    "doctrine/doctrine-bundle": "^2.5",
    "doctrine/doctrine-migrations-bundle": "^3.2",
    "doctrine/orm": "^2.10",
    "easycorp/easyadmin-bundle": "^4.0",
    "firebase/php-jwt": "^6.1",
    "friendsofsymfony/rest-bundle": "^3.3",
    "jms/serializer": "^3.17",
    "jms/serializer-bundle": "^4.0",
    "lexik/jwt-authentication-bundle": "~2.14.4",
    "nelmio/api-doc-bundle": "^4.9",
    "nelmio/cors-bundle": "^2.2",
    "oneup/flysystem-bundle": "^4.3",
    "phpdocumentor/reflection-docblock": "^5.3",
    "phpstan/phpdoc-parser": "^1.2",
    "sensio/framework-extra-bundle": "^6.1",
    "symfony/apache-pack": "^1.0",
    "symfony/asset": "5.4.*",
    "symfony/console": "5.4.*",
    "symfony/dotenv": "5.4.*",
    "symfony/expression-language": "5.4.*",
    "symfony/flex": "^1.17|^2",
    "symfony/form": "5.4.*",
    "symfony/framework-bundle": "5.4.*",
    "symfony/http-client": "5.4.*",
    "symfony/intl": "5.4.*",
    "symfony/mailer": "5.4.*",
    "symfony/messenger": "5.4.*",
    "symfony/mime": "5.4.*",
    "symfony/monolog-bundle": "^3.1",
    "symfony/notifier": "5.4.*",
    "symfony/process": "5.4.*",
    "symfony/property-access": "5.4.*",
    "symfony/property-info": "5.4.*",
    "symfony/proxy-manager-bridge": "5.4.*",
    "symfony/runtime": "^6.0",
    "symfony/security-bundle": "5.4.*",
    "symfony/sendinblue-mailer": "5.4.*",
    "symfony/serializer": "5.4.*",
    "symfony/string": "5.4.*",
    "symfony/translation": "5.4.*",
    "symfony/twig-bundle": "5.4.*",
    "symfony/validator": "5.4.*",
    "symfony/web-link": "5.4.*",
    "symfony/yaml": "5.4.*",
    "tattali/mobile-detect-bundle": "^2.2",
    "twig/extra-bundle": "^2.12|^3.0",
    "twig/twig": "^2.12|^3.0",
    "vich/uploader-bundle": "^1.19",
    "zircote/swagger-php": "^4.4"
},
"require-dev": {
    "ext-xdebug": "^3.1.0",
    "doctrine/doctrine-fixtures-bundle": "^3.4",
    "phpunit/phpunit": "^9.5",
    "symfony/browser-kit": "5.4.*",
    "symfony/css-selector": "5.4.*",
    "symfony/debug-bundle": "5.4.*",
    "symfony/maker-bundle": "^1.36",
    "symfony/phpunit-bridge": "^6.0",
    "symfony/stopwatch": "5.4.*",
    "symfony/web-profiler-bundle": "5.4.*"
},
"config": {
    "allow-plugins": {
        "symfony/flex": true,
        "symfony/runtime": true
    },
    "optimize-autoloader": true,
    "preferred-install": {
        "*": "dist"
    },
    "sort-packages": true
},
"autoload": {
    "psr-4": {
        "App\\": "src/"
    }
},
"autoload-dev": {
    "psr-4": {
        "App\\Tests\\": "tests/"
    }
},
"replace": {
    "symfony/polyfill-ctype": "*",
    "symfony/polyfill-iconv": "*",
    "symfony/polyfill-php72": "*"
},
"scripts": {
    "auto-scripts": {
        "cache:clear": "symfony-cmd",
        "assets:install %PUBLIC_DIR%": "symfony-cmd"
    },
    "post-install-cmd": [
        "@auto-scripts"
    ],
    "post-update-cmd": [
        "@auto-scripts"
    ],
    "compile": [
        "php bin/console doctrine:migrations:migrate --no-interaction --allow-no-migration"
    ]
},
"conflict": {
    "symfony/symfony": "*"
},
"extra": {
    "symfony": {
        "allow-contrib": true,
        "require": "5.4.*"
    }
}

}

The error:

[ERROR] Only attribute mapping is supported by make:entity, but the App\Entity\Test class uses a different format. If you would like this command to generate the properties & getter/setter methods, add your mapping
configuration, and then re-run this command with the --regenerate flag.

doctrine.yaml

doctrine:
dbal:
    url: '%env(resolve:DATABASE_URL)%'

    # IMPORTANT: You MUST configure your server version,
    # either here or in the DATABASE_URL env var (see .env file)
    #server_version: '13'
orm:
    auto_generate_proxy_classes: true
    naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware
    auto_mapping: true
    mappings:
        App:
            is_bundle: false
            type: annotation
            dir: '%kernel.project_dir%/src/Entity'
            prefix: 'App\Entity'
            alias: App

I've seen a lot of people have the opposite issue where the error says "Only annotations", but not my case.

Thank you for you help I really need this running now cause this school project is due next week :/

[EDIT] Here is the code from the failed entity created by doctrine

    <?php

namespace App\Entity;

use App\Repository\TestRepository;
use Doctrine\ORM\Mapping as ORM;

#[ORM\Entity(repositoryClass: TestRepository::class)]
class Test
{
    #[ORM\Id]
    #[ORM\GeneratedValue]
    #[ORM\Column()]
    private ?int $id = null;

    public function getId(): ?int
    {
        return $this->id;
    }
}

CodePudding user response:

Ok so this is a bug in MakerBundle or at least maybe they don't support annotations in latest versions.

To keep using annotations I had to specify fixed version of the bundle in composer.json (delete composer.lock and symfony.lock to be sure it won't prevent from downgrading or run composer update)

"symfony/maker-bundle": "^1.36" to "symfony/maker-bundle": "1.36.*"

CodePudding user response:

Like they said here (and here), Devs of MakerBundle remove annotation support intentionally since v1.44 in MakerBundle in favor of PHP 8's native support for metadata using attributes.

In the future, you will have to move to the new system but for the moment you can downgrade MakerBundle to 1.43. To do so, you can send:

composer require 'symfony/maker-bundle:1.43'

I hope Symfony will make it easy to move to the new system.

  • Related