spacecodeur
spacecodeur

Reputation: 2406

Symfony 4, a way for generate Entities from an Existing Database?

With Symfony 3 and its console, we can generate entities from an already existing database via the command "php bin/console doctrine:mapping:import" (very usefull !).

From symfony 4, the command "./bin/console doctrine:mapping:import" needs a bundle name but symfony 4 doesn't work with bundle now.

With the new version of symfony, is there a way I didn't see for generate entities from an existing Database (mysql by example) ? Or must I wait a new version of doctrine for have a "doctrine:mapping:import" compatible with Symfony 4 ?

I found a(n) (ugly) solution yet. I deploy a disposable symfony 3, I link the symfony 3 to my database and I generate entities in a bundle. Then I copy generates files to symfony 4. It's ugly but it works haha

Upvotes: 5

Views: 8313

Answers (1)

Oliver Adria
Oliver Adria

Reputation: 1133

You can use

php bin/console doctrine:mapping:convert --from-database annotation ./src/Entity

which should create the entities based on the database setting. Don’t forget to add the namespaces, and you will still need to add the getters and setters, but the bulk of the properties, including annotations and some of the relationships are already included. (Source)

Please also note, that Doctrine will not support this anymore in the next Doctrine version. As written in the Symfony docs

Moreover, this feature to generate entities from existing databases will be completely removed in the next Doctrine version.

Upvotes: 7

Related Questions