Creating/updating schema from Doctrine entities

◇◆丶佛笑我妖孽 提交于 2019-12-23 03:14:06

问题


I'm using Doctrine with Zend Framework. I have to create both the DB schema and the Doctrine entities with annotations.

Since the annotations already contain the information, it should be possible to create/update the schema based on them. I don't want to reinvent the wheel, so I was wondering whether that kind of logic already existed?


回答1:


You can use the doctrine CLI, for a lot of doctrine related tasks. I'm not sure how doctrine is integrated into Zend, but look for the doctrine.php, and invoke it like this:

php doctrine.php orm:schema-tool:update --force

This will update your db to match your schema definitions. You can also use

php doctrine.php orm:schema-tool:update --dump-sql

To see what SQL commands would doctrine run. See the Tools section in the doctrine docs for more information.




回答2:


There's the Doctrine SchemaTool (ORM/Tools/SchemaTool).

$meta = array(
    $this->_em->getClassMetadata('Customer')
);

$tool = new \Doctrine\ORM\Tools\SchemaTool($this->_em);
$tool->updateSchema($meta);


来源:https://stackoverflow.com/questions/7370735/creating-updating-schema-from-doctrine-entities

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!