Doctrine automatically create all the database tables?

前端 未结 2 963
天涯浪人
天涯浪人 2020-12-31 16:40

is there any way to tell doctrine automaticaly create schema tables without using this command :

doctrine:schema:update --force
相关标签:
2条回答
  • 2020-12-31 17:26

    I'm not sure what you want to do, but if you want to do it from php code, you can check how the doctrine command works and copy the code. You can find it here:

    vendor/symfony/src/Symfony/Bundle/DoctrineBundle/Command/CreateDatabaseDoctrineCommand.php
    

    If you check the execute method, you will see how it's done. Apparently you need to get a connection through the DBAL DriverManager, which gives you access to a schema object, which in turn has a createDatabase method. I have not tried this myself.

    0 讨论(0)
  • 2020-12-31 17:32

    Using SchemaTool and EntityManager you can do this:

    $schemaTool = new \Doctrine\ORM\Tools\SchemaTool($entityManager);
    $classes = $entityManager->getMetadataFactory()->getAllMetadata();
    $schemaTool->createSchema($classes);
    
    0 讨论(0)
提交回复
热议问题