Uploaded image for project: 'Doctrine Migrations'
  1. Doctrine Migrations
  2. DMIG-2

Creating columns of typ SET fails to set default value

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Labels:
      None
    • Environment:
      Doctrine 1.2.2
      MySQL 5.0.45
      PHP 5.2.5

      Description

      When writing a migration class for a table I wanted to add a new column of the SET type. I've set the notnull option and a default value, but Doctrine fails to generate the correct SQL.

      Migration function:
      public function up()

      { $options = array( 'type' => 'set', 'notnull' => 1, 'size' => 10, 'values' => array( 'value_a', 'value_b', 'value_c', ), 'default' => 'value_a ); $this->addColumn('my_table', 'new_field', 'set', Null, $options); }

      MySQL error (contains the generated SQL):
      Error #1 - SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'NOT NULL' at line 1. Failing Query: "ALTER TABLE my_table ADD new_field SET('value_a', 'value_b', 'value_c') DEFAULT NOT NULL"

      After a bit of debugging I've found the problem, Doctrine_Formatter::quote() doesn't know how to handle set. Simply adding 'set' to the switch right below 'enum' will make it work as it should.

      — lib/Doctrine/Formatter.php
      +++ lib/Doctrine/Formatter.php
      @@ -186,6 +186,7 @@ class Doctrine_Formatter extends Doctrine_Connection_Module
      case 'blob':
      case 'clob':
      case 'enum':
      + case 'set':
      case 'boolean':
      return "'" . str_replace("'","''",$input) . "'";
      }

        Activity

        Hide
        fredrik_w Fredrik added a comment -

        I hope I put this into the right project, wasn't sure if this belonged in "Doctrine 1" but this project is called "Doctrine Migrations" so here it went.

        Show
        fredrik_w Fredrik added a comment - I hope I put this into the right project, wasn't sure if this belonged in "Doctrine 1" but this project is called "Doctrine Migrations" so here it went.
        Hide
        jwage Jonathan H. Wage added a comment -

        This is actually for the Doctrine 2 Migrations project. The Doctrine 1 migrations were a part of the actual Doctrine 1 library. Everything was all coupled together in Doctrine 1. We only split things up for Doctrine 2.

        Show
        jwage Jonathan H. Wage added a comment - This is actually for the Doctrine 2 Migrations project. The Doctrine 1 migrations were a part of the actual Doctrine 1 library. Everything was all coupled together in Doctrine 1. We only split things up for Doctrine 2.
        Hide
        fredrik_w Fredrik added a comment -

        Oh, I'm sorry. Should I create a new issue under Doctrine 1 to have it fixed there?

        Show
        fredrik_w Fredrik added a comment - Oh, I'm sorry. Should I create a new issue under Doctrine 1 to have it fixed there?
        Hide
        jwage Jonathan H. Wage added a comment -

        No, I already fixed the issue. Just for future reference

        Show
        jwage Jonathan H. Wage added a comment - No, I already fixed the issue. Just for future reference

          People

          • Assignee:
            jwage Jonathan H. Wage
            Reporter:
            fredrik_w Fredrik
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: