开发者

Creating/updating schema from Doctrine entities

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

Since the anno开发者_开发百科tations 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?


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.


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);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜