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

Creating columns of typ SET fails to set default value


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


      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) . "'";


        fredrik_w Fredrik created issue -
        jwage Jonathan H. Wage made changes -
        Field Original Value New Value
        Status Open [ 1 ] Resolved [ 5 ]
        Resolution Fixed [ 1 ]


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


            • Created: