[DMIG-2] Creating columns of typ SET fails to set default value Created: 08/Jun/10  Updated: 08/Jun/10  Resolved: 08/Jun/10

Status: Resolved
Project: Doctrine Migrations
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Major
Reporter: Fredrik Assignee: Jonathan H. Wage
Resolution: Fixed Votes: 0
Labels: None

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

Comment by Fredrik [ 08/Jun/10 ]

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.

Comment by Jonathan H. Wage [ 08/Jun/10 ]

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.

Comment by Fredrik [ 08/Jun/10 ]

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

Comment by Jonathan H. Wage [ 08/Jun/10 ]

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

Generated at Wed Dec 02 00:15:48 EST 2015 using JIRA 6.4.10#64025-sha1:5b8b74079161cd76a20ab66dda52747ee6701bd6.