How to generate entities from database schema usin

2020-05-18 08:27发布

I am using "doctrine/doctrine-orm-module": "0.7.0" with ZF2.

Once I create Entities I usually run following commands to sync and generate database automatically according to my entities.

./vendor/bin/doctrine-module orm:validate-schema
./vendor/bin/doctrine-module orm:schema-tool:create

Is there a way to make this process reverse? I mean, Can I generate entities from existing database in mysql?

3条回答
Emotional °昔
2楼-- · 2020-05-18 08:36

We use a batch script:

@ECHO OFF

mkdir EXPORT
call .\vendor\bin\doctrine-module orm:convert-mapping --force --from-database annotation ./EXPORT/
call .\vendor\bin\doctrine-module orm:generate-entities ./EXPORT/ --generate-annotations=true

pause 

orm:convert-mapping and orm:generate-entities is probably what you are looking for.

查看更多
爱情/是我丢掉的垃圾
3楼-- · 2020-05-18 08:55

There's a nice blog written on this here

Edit: It can be done by using the commands below:
1. convert-mapping (Table & Entity):

  ./vendor/doctrine/doctrine-module/bin/doctrine-module orm:convert-mapping --namespace="Album\\Entity\\" --force  --from-database annotation ./module/Album/src/


2. Generates getter and setter

   ./vendor/doctrine/doctrine-module/bin/doctrine-module orm:generate-entities ./module/Album/src/ --generate-annotations=true
查看更多
4楼-- · 2020-05-18 08:56

Try just it

doctrine orm:convert-mapping -f --from-database annotation entities/

doctrine orm:generate-entities --generate-annotations="true" entities/

http://wildlyinaccurate.com/useful-doctrine-2-console-commands/

查看更多
登录 后发表回答