Closed cmukanisa closed 2 years ago
`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:
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
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)
https://github.com/symfony/symfony-docs/issues/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
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
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:
--
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.
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!
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
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).
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 https://github.com/symfony/maker-bundle/issues/841 or https://stackoverflow.com/questions/73073080/symfony-5-only-attribute-mapping-is-supported-by-makeentity
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.
Well, too bad for LTS... on the other hand, maintaining multiple branches is a pain, I know.
I had same problem and solved by adding type field with attribute value like this
App:
type: attribute
...
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
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.
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
[ERROR] Only attribute mapping is supported by make:entity, but theApp\Entity\User class uses a different
format. If you would like this command to generate the properties & getter/setter methods, add your mapping--regenerate flag.
configuration, and then re-run this command with the
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