Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Note the problem described in http://drupal.org/node/99005. It looks like in some cases, adding a default value to a text/blob field could cause SQL errors. Looking at the code in content_admin.inc, I'm not sure we're handling this correctly. It looks like we're providing a '' default value if none is supplied even for text fields. This needs investigation, but I don't have time to look into it now, so I'm posting this as an issue for whoever has time to work on it.
Comment | File | Size | Author |
---|---|---|---|
#9 | content_admin.inc_6.patch | 705 bytes | yched |
#4 | text.module_5.patch | 588 bytes | yched |
Comments
Comment #1
KarenS CreditAttribution: KarenS commentedBTW, the relevant function is content_db_add_column() which is the code that creates the db field columns.
Comment #2
Heine CreditAttribution: Heine commentedMySQL doesn't support DEFAULT values on TEXT or BLOB columns. When running in strict mode MySQL 5 will complain (loudly). We just removed default values from core.
Comment #3
yched CreditAttribution: yched commentedAs a matter of fact, I was not aware of the post Karen mentioned, but I saw the core patch a few days ago, and investigated text.module.
From my tests, MySQL 4.1 was in fact rejecting
ALTER TABLE `foo` ADD `bar` LONGTEXT DEFAULT 'baz' ;
, butaccepted with no errors
ALTER TABLE `foo` ADD `bar` LONGTEXT DEFAULT '' ;
andALTER TABLE `foo` ADD `bar` LONGTEXT DEFAULT NULL ;
(the latter if the column is not specified NOT NULL, of course...)So I did not touch anything in text.module, and simply added a comment saying 'this should not work but looks okay for now' (I did not commit that yet...)
But if MySQL 5 rejects it, I guess we have to correct this.
Comment #4
yched CreditAttribution: yched commentedAttached patch should correct this - before committing, I'd like someone with a MySQL 5 install to confirm, though...
Patch is for 5 branch, but should apply easily on 4.7
Comment #5
yched CreditAttribution: yched commentedComment #6
KarenS CreditAttribution: KarenS commentedyched, I was also looking at the content_db_add_column() function. I think we need a fix there so that default values don't get attached to text fields. That would keep any field module from inadvertently trying to provide a default value.
Also, I assume that providing no default value is also the right behavior for postgres??
Comment #7
KarenS CreditAttribution: KarenS commentedAnd if we alter that function we can remove the default completely rather than trying to do default NULL, just in case that is a problem in some dbs.
Comment #8
yched CreditAttribution: yched commentedMaybe you're right.
After all, it's a 'db-type' specific issue, and it's probably up to content.module to handle the db specifics.
I still think we have to keep the 'default' param in the field definition, though.
Comment #9
yched CreditAttribution: yched commentedAttached patch does the check in the mysql part of content_db_add_column().
(from the online reference, pgsql seems OK with default values for any column type)
This cancels my previous patch for text.module, which is not needed - and not wanted, aamof.
Comment #10
KarenS CreditAttribution: KarenS commentedLooks good to me. Committed. Thanks yched.
Comment #11
(not verified) CreditAttribution: commented