Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-2788

Create Table If Not Exists - doctrine:schema:update

    Details

    • Type: Improvement Improvement
    • Status: Open
    • Priority: Minor Minor
    • Resolution: Unresolved
    • Affects Version/s: 2.2.3
    • Fix Version/s: None
    • Component/s: Tools
    • Security Level: All

      Description

      I am not positive if this issue is in the correct project. Sorry if I placed it in the wrong area.

      I was wondering if it would be possible to have the doctrine:schema:update command updated to use CREATE IF NOT EXISTS for tables that already exist.

      For example, here is my setup:

      Author.php
          /**
           * The relationship between an author and its associated book entities.
           *
           * @ORM\ManyToMany(targetEntity="Book")
           * @ORM\JoinTable(name="authors_books",
           *     joinColumns={@ORM\JoinColumn(name="book_id", referencedColumnName="id")},
           *     inverseJoinColumns={@ORM\JoinColumn(name="author_id", referencedColumnName="id")}
           * )
           */
          protected $books;
      

      The above code is an example, so the exact column names may not be 100% correct. The import aspect is the join table name. If that table already exists in the database, I will get the following error when I run the doctrine:schema:update --dump-sql command:

      [Doctrine\DBAL\Schema\SchemaException]
      The table with the name 'authors_books' already exists.

      This is because it is trying to CREATE TABLE 'authors_books' and that table is already in the database. Could the command instead use CREATE TABLE IF NOT EXISTS 'authors_books' when "IF NOT EXISTS" is available for the configured database type?

      Thanks!

        Activity

        There are no comments yet on this issue.

          People

          • Assignee:
            Benjamin Eberlei
            Reporter:
            jayem
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated: