0

I am adding 2 columns to an existing table using hook_update_N function as below:

function cca_update_8904(&$sandbox){



   $connection = \Drupal::database();
      $schema = $connection->schema();
      $spec = array(
        'type' => 'integer',
        'description' => "criteriaflag",
        'length' => 20,
        'not null' => FALSE,
        'default' => 0,
      );
    
      $schema->addField('cca_program', 'criteriaflag', $spec);
    //
      $spec = array(
        'type' => 'text',
        'description' => "criteriaflagcode",
        'length' => 20,
        'not null' => FALSE,
      );
    
      $schema->addField('cca_program', 'criteriaflagcode', $spec);
    
    \Drupal::entityDefinitionUpdateManager()->applyUpdates();
    
    }

When I run update.php I get to see the below error:

Failed: Drupal\Core\Database\DatabaseExceptionWrapper: 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 'NULL DEFAULT 0 COMMENT 'criteriaflag'' at line 1: ALTER TABLE {program} ADD `criteriaflag` NULL DEFAULT 0 COMMENT 'criteriaflag'; Array ( ) in cca_update_8904() (line 702 of /vagrant/web/modules/cca/cca.install).

Any help on how this can be fixed?

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.