ShanjayG
ShanjayG

Reputation: 1023

Symfony 4 Doctrine, creating Entities from database table

New to Symfony here I am following this tutorial about mapping db tables to entities. I created the blog_post and blog_comment tables in my db. I tried running this php bin/console doctrine:mapping:import --force AppBundle xml which spit out the following error.

Bundle "AppBundle" does not exist or it is not enabled. Maybe you forgot to 
add it in the registerBundles() method of your App\Kernel.php file? 

My doctrine.yaml is pretty much out of the box.

Doctrine.yaml

doctrine:
dbal:
    # configure these for your database server
    driver: 'pdo_mysql'
    server_version: '5.7'
    charset: utf8mb4

    # With Symfony 3.3, remove the `resolve:` prefix
    url: '%env(resolve:DATABASE_URL)%'
orm:
    auto_generate_proxy_classes: '%kernel.debug%'
    naming_strategy: doctrine.orm.naming_strategy.underscore
    auto_mapping: true
    mappings:
        App:
            is_bundle: true
            type: annotation
            dir: '%kernel.project_dir%/src/Entity'
            prefix: 'App\Entity'
            alias: App

I created the App.php Class under src/Entity/ and added a line under bundles.php but still get an error. The line I added on bundles.php is App\Entity\App::class=>['all' => true], since that is the defined namespace of my App.php class.

Another error I get is

PHP Fatal error:  Uncaught 
Symfony\Component\Debug\Exception\ClassNotFoundException: Attempted to load 
class "App" from namespace "App\Entity\App".
Did you forget a "use" statement for another namespace? in 
/var/www/html/quick_tour/src/Kernel.php:32

Upvotes: 0

Views: 1369

Answers (2)

pedram shabani
pedram shabani

Reputation: 1680

you must use App rather than AppBundle on Symfony 4

Upvotes: 1

ShanjayG
ShanjayG

Reputation: 1023

Found similar situation to mine in here as well.

Since Symfony 4 Use App instead of Appbundle

Upvotes: 1

Related Questions