Symfony 3 Generate Entity Class From an Existing database using Doctrine Command

Generate Metadata files using Doctrine command, Metadata files describe the entity class to generate based on database tables. You can generate xml or yml format.

php bin/console doctrine:mapping:import --force AppBundle xml


php bin/console doctrine:mapping:import --force AppBundle yml

You can see your metadata files are created under the following path based on the database tables you have in your database.


Once Metadata files are generated, now you can create your entity classes using the following Doctrine command. Following two command will generate the Entity classes for each table including annotation, setter and getter methods.

php bin/console doctrine:mapping:convert annotation ./src

php bin/console doctrine:generate:entities AppBundle

Now you can see the created Entity files under following directory.



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s