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

make:user gives 'Cannot find the entity manager for class "App\Entity\User" ' if App\Entity is not empty #1158

Closed
Adi-18 opened this issue Jul 25, 2022 · 8 comments · Fixed by #1475
Labels

Comments

@Adi-18
Copy link

Adi-18 commented Jul 25, 2022

Replicated on a fresh Symfony 6.1 installation
symfony/maker-bundle v1.44.0

Error: 'Cannot find the entity manager for class "App\Entity\User" '
after command 'symfony console make:user' and if there is already an Entity in App\Entity

@jrushlow
Copy link
Collaborator

Howdy @Adi-18 - i'm unable to replicate this locally. Can you provider a simple re-producer app that demonstrates this error?

Another thing to check out is your doctrine.yaml config:

In a fresh 6.1 app, it should look something like:

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

For the user entity (Using Postgres)

#[ORM\Entity(repositoryClass: UserRepository::class)]
#[ORM\Table(name: '`user`')]
class User implements UserInterface, PasswordAuthenticatedUserInterface
{
    ...

Also, at what point are you getting that error message when running the make:user command?

@Adi-18
Copy link
Author

Adi-18 commented Aug 4, 2022

Hi @jrushlow
I attached a zip file with my demo project. So I hope there are all information you need.
playground.zip

Error:
image

@gbtux
Copy link

gbtux commented Aug 10, 2022

Hi,
Same bug here, but with a solution ;)

Check your Doctrine config, it fix the problem in my project:
image

I don't have the "doctrine.orm.mappings.App.type: attribute" set ...and have entities with annotations, not attributes....

Thanks to : this post in stackoverflow

@Preciel
Copy link

Preciel commented Aug 10, 2022

I can confirm @gbtux answer.

It seems that MakerBundle will write either attributes or annotations based on our development environment.
If doctrine.orm.mappins.App.type value, in config/packages/doctrine.yaml, doesn't match your environment, then the error occur.

I produced the opposite, doctrine.orm.mappins.App.type was set to annotation, but MakerBundle was using attributes.

@Seesicht-IT
Copy link

Seesicht-IT commented Aug 26, 2022

I ran into the same issue.

I set up a completely new installation of Symfony 5.4.11 with Maker-Bundle 1.45.0. And I am already running on PHP 8.1.0. and therefore set require.php to 8.1 in composer.json.

With this setup, I run into the mentioned error.

When I add adding doctrine.orm.mappins.App.type: attribute to the doctrine.yaml file, then it works fine.
When I set it to adding doctrine.orm.mappins.App.type: annotation to remove the line then I run into the error.

@DebasmitaDasBot
Copy link

I confirm that the solution given by @gbtux worked fine for me. Thanks!

@jrushlow
Copy link
Collaborator

Yes that makes sense. We dropped Annotation support back in July -> https://github.com/symfony/maker-bundle/releases/tag/v1.44.0

Thinking of how we can provide better DX to say "Hey, you're using annotations, maker only uses attributes..."

@oversong1
Copy link

I'm from Brazil, I used the tips from all of you here and made the following modification, I added the attribute "type: attribute" and it worked, I also did the test with the annotation, but for this case it didn't work.
orm:
auto_generate_proxy_classes: true
enable_lazy_ghost_objects: 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
type: attribute
# type: annotation

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

Successfully merging a pull request may close this issue.

7 participants