title: Doctrine: How to create entity-related tables on demand? (if i want to keep one SQL schema source)
body: <p><strong>Is there a way to tell Doctrine the name of a number of entities and it creates their related tables (incl. foreign keys etc.)?</strong></p>
  
  <hr>
  
  <p><strong>My scenario:</strong></p>
  
  <p>I want to have annotations at my Doctrine entities as the only source for my database schema. Which means, that for instance for tests, i don't want to maintain a <em>copy</em> of these information in a SQL file or something.</p>
  
  <p>To be clear, i mean annotations in entity classes like the following:</p>
  
  <pre class="lang-php prettyprint-override"><code>&lt;?php 
  
  namespace App\Entity;
  
  /**
   * @ORM\Entity(repositoryClass="App\Repository\UserRepository")
   * @UniqueEntity(fields={"email"}, message="There is already an account with this email")
   *
   * @ORM\Table(
   *      uniqueConstraints={
   *          @ORM\UniqueConstraint(name="email", columns={"email"})
   *      }
   * )
   */
  class User
  {
      /**
       * @ORM\Id()
       * @ORM\GeneratedValue()
       * @ORM\Column(type="integer")
       */
      private $id;
  
      /**
       * @ORM\Column(type="string", length=180, nullable=false)
       */
      private $email;
  
      // ...
  }
  </code></pre>
  
  <hr>
  
  <p><strong>What i would like to do:</strong></p>
  
  <p>In my tests i would like to create the table for, lets say <code>User</code>, like:</p>
  
  <pre class="lang-php prettyprint-override"><code>&lt;?php
  
  
  namespace App\Test;
  
  use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
  
  class SomeTestCase extends KernelTestCase
  {
      public function setUp()
      {
          // ...
  
          $this-&gt;entityManager = $kernel-&gt;getContainer()
              -&gt;get('doctrine')
              -&gt;getManager();
      }
  
      public function test1()
      {
          // Is there a function available which has this functionality?
          $this-&gt;entityManager-&gt;createTableForEntity('App\Entity\User'); // &lt;---------
  
          // ...
      }
  }
  
  </code></pre>
  
  <p><strong>Is that possible?</strong> If not, even creating all tables at once is fine for me.</p>
  
  <p><strong>Is there another way to achieve it?</strong></p>