5

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.

3
  • Did you try to use the maker bundle: symfony.com/doc/current/doctrine/reverse_engineering.html ? Commented Oct 4, 2022 at 12:04
  • Thats what i tried right but the relations and factories are not produced. Commented Oct 4, 2022 at 15:43
  • 1
    @Hannes In general Doctrine ORM is intended to be developed within an application by using an Entity first approach. There are a great deal of things that will be broken when relying on mapping out the entities from a database because of limitations imposed by the ORM. For example DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP and other expressions. While it may be possible, if you are not intimately familiar with the ORM you will run into problems. Commented Nov 1, 2022 at 22:02

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

1 Comment

I had already tried that. But it also means that I can't create the relations or the factories with it. I have to do that manually... is that correct or is there an automatism for that?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.