This is an issue I originally thought was a Workflow module bug. But, after stepping through, I now believe this to be a bug in the MySQL DB Driver.
I was looking at these issues discussing the same thing:
- https://www.drupal.org/project/workflow/issues/2947266
- https://www.drupal.org/project/workflow/issues/2884417
In the workflow_update_7017() update hook introduced in the 7.x-2.x-dev release, it tries to remove the current primary key and re add a new one with the column name 'tid'. The specs of the new column seem to be fine.
$spec = array(
'type' => 'serial',
'not null' => TRUE,
);
$keys_new = array(
'primary key' => array('tid'),
);
However, whilst running db_add_field()
, an exception is thrown stating
All parts of a PRIMARY KEY must be NOT NULL
. I stepped through until I came across the schema.inc file in the mysql driver directory (includes/database/mysql/shcema.inc). In the addField
method, it checks if the$specs
of the new column specify that it cannot be NULL and doesn't have a default value set.
if (!empty($spec['not null']) && !isset($spec['default'])) {
$fixnull = TRUE;
$spec['not null'] = FALSE;
}
If this statement is true, it will fix the query to say that the column can be NULL, but still includes the primary key condition. This causes MySQL to reject the change because in 5.7.x a primary key cannot be NULL (which makes sense). This statement seems wrong, because it doesn't actually check what the value of the 'not null' key is. If the code looked like the following:
if (!empty($spec['not null']) && $spec['not null'] == FALSE && !isset($spec['default'])) {
$fixnull = TRUE;
$spec['not null'] = FALSE;
}
Then it would only fix the query if there was no given default value AND the column could be NULL.