Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-2560

Schema tool invalid DDL syntax for default values

    Details

    • Type: Bug Bug
    • Status: Reopened
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: 2.3.4
    • Fix Version/s: None
    • Component/s: None
    • Security Level: All
    • Labels:
    • Environment:
      Postgresql

      Description

      Not sure if this is Postgresql specific or not, but here are the reproduction steps:

      Have a table with a column setup like so:

      ALTER TABLE usr ADD COLUMN contact_count integer;
      ALTER TABLE usr ALTER COLUMN contact_count SET NOT NULL;
      ALTER TABLE usr ALTER COLUMN contact_count SET DEFAULT 0;
      

      Have a Entity Column Definition like so:

          /**
           * @var integer $contactCount
           *
           * @ORM\Column(name="contact_count", type="integer", nullable=false)
           */
          private $contactCount = 0;
      
      

      orm:schema-tool:update will generate the following SQL:

      ALTER TABLE usr ALTER contact_count SET ;
      

      adding

      options={"default":0}
      

      to the column definition results in no sql being generated (correctly I assume)

        Activity

        Hide
        Marco Pivetta added a comment -

        The ORM doesn't support default column values.
        That's fine-tuning you can do on the column definitions.

        Your "workaround" is actually the correct way of dealing with this kind of DDL change.

        Show
        Marco Pivetta added a comment - The ORM doesn't support default column values. That's fine-tuning you can do on the column definitions. Your "workaround" is actually the correct way of dealing with this kind of DDL change.
        Hide
        Ben Davies added a comment -

        I realise the ORM doesn't support default values, but the point is that the schematool picks up a diff in the columns, tries to generate a diff, and generates an invalid sql statement. Surely that is a bug?

        Show
        Ben Davies added a comment - I realise the ORM doesn't support default values, but the point is that the schematool picks up a diff in the columns, tries to generate a diff, and generates an invalid sql statement. Surely that is a bug?
        Hide
        Marco Pivetta added a comment -

        Ben Davies the DBAL is responsible for generating this wrong DDL... Are you able to reproduce this in DBAL only?

        Show
        Marco Pivetta added a comment - Ben Davies the DBAL is responsible for generating this wrong DDL... Are you able to reproduce this in DBAL only?
        Hide
        Ben Davies added a comment -

        Happy to try.

        Show
        Ben Davies added a comment - Happy to try.
        Show
        Ben Davies added a comment - here you go https://github.com/bendavies/dbal/blob/DBAL-561/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL561Test.php

          People

          • Assignee:
            Marco Pivetta
            Reporter:
            Ben Davies
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated: