Symfony 4 - a way to generate entities from an existing database?

Using Symfony 3 and its console, we can generate objects from an existing database using the command "php bin / console doctrine: mapping: import" (very useful!).

From symfony 4, the "./bin/console doctrine: mapping: import" command needs a package name, but symfony 4 now does not work with the package.

With the new version of symfony, is there a way that I have not seen to create entities from an existing database (mysql example)? Or should I wait for a new version of the doctrine so that "doctrine: mapping: import" is compatible with Symfony 4?

I found a (n) (ugly) solution. I am deploying one-time symfony 3, I am linking symfony 3 to my database and generating entities in a bundle. Then I copy the files to symfony 4. This is ugly, but it works haha

+4
source share
1 answer

you can use

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

which should create objects based on database settings. Remember to add namespaces, and you will still need to add getters and setters, but most of the properties, including annotations and some relationships, are already included. ( Source )

Also note that Doctrine will no longer support this in the next version of Doctrine. As recorded in symfony docs

, Doctrine.

+1

Source: https://habr.com/ru/post/1690363/


All Articles