Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ERROR] Only attribute mapping is supported by make:entity, but the <info>App\Entity\User</info> 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 <info>--regenerate</info> flag. #1152

Closed
cmukanisa opened this issue Jul 15, 2022 · 14 comments

Comments

@cmukanisa
Copy link

[ERROR] Only attribute mapping is supported by make:entity, but the App\Entity\User 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.

Today, once I updated my project to the latest version of 5.4.* (5.4.10), I can no longer generate the entities nor can I add to those that already exist

image
Screenshot 2022-07-15 at 11-15-57 JASSE 🏩🥼 SAINT JOSEPH DE MADAILA PHARMACIE HEALTHCAROLOGY Votre partenaire numérique Remedde ™

@cmukanisa
Copy link
Author

cmukanisa commented Jul 15, 2022

`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
            dir: '%kernel.project_dir%/src/Entity'
            prefix: 'App\Entity'
            alias: App

when@test:
doctrine:
dbal:
# "TEST_TOKEN" is typically set by ParaTest
dbname_suffix: '_test%env(default::TEST_TOKEN)%'

when@prod:
doctrine:
orm:
auto_generate_proxy_classes: false
query_cache_driver:
type: pool
pool: doctrine.system_cache_pool
result_cache_driver:
type: pool
pool: doctrine.result_cache_pool

framework:
    cache:
        pools:
            doctrine.result_cache_pool:
                adapter: cache.app
            doctrine.system_cache_pool:
                adapter: cache.system

`

MY DOCTRINE.YAML FILE
image

@NeuralClone
Copy link

NeuralClone commented Jul 16, 2022

I recently ran into this problem as well and was a bit baffled as to what had changed. It looks like annotation support was intentionally removed in v1.44 in favor of PHP 8's native support for metadata using attributes:

https://github.com/symfony/maker-bundle/blob/v1.44.0/CHANGELOG.md (see #1126)

The current Symfony documentation still shows annotations as being supported by MakerBundle, which just adds to the confusion:

https://symfony.com/doc/current/doctrine.html#creating-an-entity-class (for example)

symfony/symfony-docs#16877

I can confirm that this particular feature still works in v1.43. So if you still need annotation support with this bundle, you can limit your dev dependency to <=1.43 and that'll hopefully do the trick. Make sure to run composer update after making that change so it'll downgrade the package. Otherwise, you can read more about attribute mapping in Doctrine here:

https://www.doctrine-project.org/projects/doctrine-orm/en/2.11/reference/attributes-reference.html

@cmukanisa
Copy link
Author

Thank you @NeuralClone
It's working on downgrading to <=1.43

But I Will need to use attribute in the future,
It's will be obligatory to change all annotations in my project to attribute ?
It's will be difficult because i have around 300 entities with relationships

@NeuralClone
Copy link

NeuralClone commented Jul 16, 2022

Edit: After playing with this some more, it looks like you'll need a custom mapping driver if you want to use both annotations and attributes at the same time:

https://stackoverflow.com/questions/68195822/doctrine-orm-2-9-use-both-annotationdriver-and-attributedriver-to-parse-entity-m

--

You're welcome, @cmukanisa! It seems that everything is headed toward attribute mapping since that's where PHP is at. Symfony is replacing annotations with the PHP approach and Doctrine has been steadily moving that way too.

The syntax for attribute mapping is very similar to annotation mapping. Doctrine's syntax in particular is almost identical to annotations. So it may not be as bad as it seems on the surface.

Rector might be worth a look for converting your existing model over to using attribute mapping.

@jrushlow
Copy link
Collaborator

The error is caused by the use of annotations for doctrine entities. Starting w/ v1.44.0 - MakerBundle only supports using attributes with entities. We have a PR up to correct the Symfony docs showing this change.

I highly recommend using rector to upgrade your existing entities from annotations to attributes. I've used this myself in many projects and it works great! Checkout https://getrector.org/blog/how-to-upgrade-annotations-to-attributes for more information. Thanks!

javiereguiluz added a commit to symfony/symfony-docs that referenced this issue Jul 22, 2022
…ker-bundle (jrushlow)

This PR was squashed before being merged into the 5.4 branch.

Discussion
----------

[Doctrine] show attributes instead of annotations for maker-bundle

Starting w/ v1.44.0 - maker bundle only supports attribute mapping w/ entities.

Related to symfony/maker-bundle#1152

Commits
-------

50ddde9 [Doctrine] show attributes instead of annotations for maker-bundle
@olberger
Copy link

What's expected from users of PHP 7 and Symfony 5.4 ? They'll have to manually downgrade to v1.43 and figure out why the docs mention something that isn't compatible with PHP 7 ?

Symfony 5.4 LTS is supposed to "Requires: PHP 7.2.5 or higher" https://symfony.com/releases/5.4

Heading too fast without a standard dependency on version 1.43 for Symfony 5.4 will render things difficult for existing users on LTS. Yes, they should prepare for upgrade to PHP 8 some day... but upgrades on LTS should be flawless IMHP

@wouterj
Copy link
Member

wouterj commented Oct 23, 2022

Versions higher than 1.43 require PHP 8.0 in composer.json, so Composer will automatically install 1.43 in a PHP 7.4 environment (unless you run Composer using the --ignore-platform-reqs flag which explicitly disables platform checks from Composer).

@olberger
Copy link

Right, maybe users of PHP 7 are fine, then the issue is with Symfony 5.4 and users of PHP 8 then. See numerous reports like #841 or https://stackoverflow.com/questions/73073080/symfony-5-only-attribute-mapping-is-supported-by-makeentity

@wouterj
Copy link
Member

wouterj commented Oct 23, 2022

The maker bundle stopped supporting annotations. Supporting multiple formats causes significant complexity and overhead in the maintenance of this bundle. Every application using PHP 8 is recommended to use attributes and PHP 7 has reached end-of-life, so it makes sense to drop support.

If you need annotation support, you can stick to using version 1.43. Maybe the error message can be upgraded to say this, but other than that I think the message is already quite clear.

@olberger
Copy link

Well, too bad for LTS... on the other hand, maintaining multiple branches is a pain, I know.

@kakhavk
Copy link

kakhavk commented Oct 29, 2022

I had same problem and solved by adding type field with attribute value like this

      App:
        type: attribute
        ...

@marinhekman
Copy link

marinhekman commented Nov 11, 2022

As @kakhavk mentioned as well.

I still had a "type: annotation" configured in my doctrine configuration. You just have to remove that line or change it to "type: attribute" to set it to use attributes instead

 # config/packages/doctrine.yaml
 doctrine:
     orm:
         mappings:
             App:
                type: annotation # <----------- remove this line

@nstCactus
Copy link

nstCactus commented Feb 14, 2023

I hear your arguments about maintenance of the bundle, PHP 8 support and all. But simply bumping the major version of the bundle to 2.0.0 would have avoided a lot of headaches.

@mateusfmello
Copy link

As @kakhavk mentioned as well.

I still had a "type: annotation" configured in my doctrine configuration. You just have to remove that line or change it to "type: attribute" to set it to use attributes instead

 # config/packages/doctrine.yaml
 doctrine:
     orm:
         mappings:
             App:
                type: annotation # <----------- remove this line

Just removing it didn't solve the problem, I had to inform "attribute" in type.
As guided by @kakhavk

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants