Answer the question
In order to leave comments, you need to log in
How to automatically create tables in Doctrine?
Good afternoon,
is it possible to somehow force Doctrine (the latest stable) to automatically create tables (as well as fields in existing tables) for entities?
* Even if I myself have to describe somewhere the correspondence of database field types to Doctrine field types
Answer the question
In order to leave comments, you need to log in
Such code can be used anywhere, not necessarily in Symfony, for example in Silex / Slim. In production, it should not, of course, be executed. An important point: in the database it will leave only those tables that are listed in $classes, the rest will crash.
// \Doctrine\ORM\EntityManager $em
$tool = new \Doctrine\ORM\Tools\SchemaTool($em);
$classes = array(
$em->getClassMetadata('Entities\Page'),
$em->getClassMetadata('Entities\Catalog'),
$em->getClassMetadata('Entities\CatalogOption'),
$em->getClassMetadata('Entities\WebForm'),
);
$tool->updateSchema($classes);
of course it is possible. Not automatically, but on demand.
dock in native
docs.doctrine-project.org/projects/doctrine-orm/en/2.0.x/reference/tools.html
dock in Russian, implementation in symfony2
symfony-gu.ru/documentation/ru/html/book/doctrine .html
examples
habrahabr.ru/post/125469/
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question