1

Hi I'm on Symfony 5 and I'll like to generate php entities and update the scheme from a orm.xml file.

I think it worked before with doctrine:generate:entities command.

Any solution? Thanks in advance

dvillodres
  • 11
  • 1
  • According to the [Doctrine docs](https://www.doctrine-project.org/projects/doctrine-orm/en/2.7/reference/tools.html#entity-generation), Doctrine itself still supports generating entities from a database. If you really want to do this then you might give it a try. You need to setup a couple of Doctrine config files and run vendor/bin/doctrine. The link also explains some of the limitations. – Cerad Dec 31 '20 at 14:37

1 Answers1

2

The command doctrine:generate:entities was removed. The Doctrine ORM team does not encourage creating entities from existing schema and therefore deprecated that functionality in the ORM.

With the MakerBundle you can create entities, but as far as I know it won't create them from a schema, so you have to manually create each Entity, which admittedly can be annoying if you just want to generate them based on the existing schema anyway. Alternatively you can create a new "legacy" Symfony application (e.g. based on version 3.4 as this should still have the command), create the entities from the schema as described in the docs, and then copy the generated entities over into your project. You will likely also have to run a search & replace for AppBundle\Entity -> App\Entity.

dbrumann
  • 16,803
  • 2
  • 42
  • 58
  • Thanks, thats look too hard for maintain the model. I cant understand why symfony deprecated it and didn't supply a new feature. – dvillodres Dec 31 '20 at 11:20
  • There are many reasons. Some, that cause the output to be incomplete, are stated in the docs: "Doctrine is able to convert approximately 70-80% of the necessary mapping information based on fields, indexes and foreign key constraints. Doctrine can’t discover inverse associations, inheritance types, entities with foreign keys as primary keys or semantical operations on associations such as cascade or lifecycle events." – dbrumann Dec 31 '20 at 12:26