简体   繁体   中英

How to use an existing Database with Symfony 6 and Doctrine

I want to use an existing MariaDB with a new Symfony 6 project and Doctrine.

Unfortunately, I don't understand how to create the entities and repository from an existing database. The database is very complex and has a lot of relations. Is there an importer for this?

The following command seems to be deprecated. It works, but only creates the entities (but probably not completely correct).

symfony console doctrine:mapping:import "App\Entity" annotation --path=src/Entity

Thanks for your help.

You can use this kind of command:

symfony console doctrine:mapping:import "App\Entity" annotation --path=src/Entity

But be aware that this solution is deprecated.

What Symfony's team recommend is to create you entities yourself using the maker bundle.

Keep in mind that the maker only generate PHP classes, so you shall be able to reproduce your entities this way. It's gonna take you some time, but it's the best way to do actually.

Just be careful with the naming of your relations (especially with the many to many pivot tables) wich may not be as generic as what the maker bundle generate

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM