If table has an unsigned float with no size set then the resulting generated schema array has the precision and scale fields as blanks. This generates a mysql error on installation of the schema.
After creating a table with FLOATs as two fields (one was unsigned and one was signed) I noticed that the unsigned FLOAT was being set improperly by the schema module. The Schema module kept trying to set precision and scale but without setting any value to them.
column score - differences on: scale, precision
declared: array('description' => t('TODO: please describe this field!'), 'type' => 'float', 'unsigned' => TRUE, 'not null' => TRUE)
actual: array('description' => t('TODO: please describe this field!'), 'type' => 'float', 'unsigned' => TRUE, 'not null' => TRUE, 'precision' => '', 'scale' => '')
| Comment | File | Size | Author |
|---|---|---|---|
| #5 | schema-1271620-fix-blank-precision-scale-5.patch | 1.83 KB | jayelless |
| #1 | mysql_float_precision.patch | 737 bytes | Kevin Rogers |
Comments
Comment #1
Kevin Rogers commentedI've just run into the same issue.:
There seems to be a missing test to check if a numeric/float/double column has a precision.
The attached patch corrects the problem for me.
Comment #2
alive2000 commentedThis bug present in 7.x-1.0-beta3 too. Only with unsigned floats.
Comment #3
gregglesUpdating to 7.x-1.x-dev based on comment #2. Is this still relevant in the latest dev? Marking needs more information to answer that question.
Comment #4
jayelless commentedI have found this problem on an install of Drupal Commons in the radioactivity module. The Schema report advises that the energy column of the radioactivity_history table differs in precision and scale.
I have taken a different approach to that in comment 2 and generated a patch that addresses the issue of a column attribute key that is neither NULL nor FALSE but is an empty string by adding a test for an empty value in the relevant part of the code.
I have also taken the opportunity to re-format the complex if statement to make it easier to understand.
Patch attached.
Comment #5
jayelless commentedWoops! There was a test in the if statement that should not have been there. I have now removed it and re-rolled the patch.