Doctrine 1
  1. Doctrine 1
  2. DC-969

When I add a text field to a mysql table the migration code generated fails

    Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Minor Minor
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: None
    • Labels:
      None
    • Environment:
      Linux, Symfony 1.4, Doctrine 1.2

      Description

      I am using a database designed using schema.yml with a MySql Server.

      When I add a field of type text the generated code for the migrations (using diff) is as follows:

      $this->addColumn('<tableName>', '<fieldName>, 'text', '', array(
      'notnull' => '',
      ));

      Which produces a MySQL error like this:

      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 ')' at line 1. Failing Query: "ALTER TABLE <tableName> ADD <fieldName> text()"

      The solution I found was to manipulate manually the generated class to use an addColumn like this:

      $this->addColumn('<tableName>', '<fieldName>, 'text', null, array(
      'notnull' => '',
      ));

      Which would generate an SQL statement like this:

      ALTER TABLE <tableName> ADD <fieldName> text

      Which works fine with MySQL, don't know about other RDBMS

        Activity

        Hide
        Siegfried DuDragon added a comment -

        My understanding is that you need to put a size to the text so it will choose between tinytext, text, mediumtext, bigtext, so instead of
        $this->addColumn('<tableName>', '<fieldName>, 'text', '', array(
        'notnull' => '',
        ));
        use
        $this->addColumn('<tableName>', '<fieldName>, 'text', '<somenumber>', array(
        'notnull' => '',
        ));

        Show
        Siegfried DuDragon added a comment - My understanding is that you need to put a size to the text so it will choose between tinytext, text, mediumtext, bigtext, so instead of $this->addColumn('<tableName>', '<fieldName>, 'text', '', array( 'notnull' => '', )); use $this->addColumn('<tableName>', '<fieldName>, 'text', '<somenumber>', array( 'notnull' => '', ));

          People

          • Assignee:
            Jonathan H. Wage
            Reporter:
            Mauro Chojrin
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated: