In strict mode, MySQL cannot accept an empty string when a field's "not null" property is set to TRUE. This can cause MySQL errors to be thrown in certain situations.

As far as I know there is no downside to setting 'not null'->FALSE, many CCK core fields do that now.

Patch attached, this is my first patch submission! Let me know if you need anything :)

CommentFileSizeAuthor
#3 phone.module.6.x.patch187 bytesdarrellduane
phone.module.patch756 bytesgdd

Comments

neilnz’s picture

Version: 5.x-1.5 » 6.x-2.8

I can confirm this is also an issue with the D6 version. Running on a PostgreSQL database, this prevents the node from being created because the database says you're trying to insert null into a not-null field. Example error from watchdog:

# warning: pg_query() [function.pg-query]: Query failed: ERROR: null value in column "field_phone_home_value" violates not-null constraint in /var/www/signon/includes/database.pgsql.inc on line 139.
# user warning: query: INSERT INTO content_type_profile (vid, nid, field_firstname_value, field_lastname_value, field_signup_method_value, field_allow_contact_value, field_address_aname, field_address_street, field_address_additional, field_address_city, field_address_province, field_address_country, field_address_postal_code, field_address_is_primary, field_phone_home_value, field_phone_mobile_value) VALUES (403, 403, 'Test 399', 'User 399', 'import', 1, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL) in /var/www/signon/sites/all/modules/cck/content.module on line 1207.

The trigger for this error is either programmatically creating nodes without the phone field set (which is fine if it's not a "required" field), for example using node_import to import content. Another cause is using something like the content_permissions module that ships with CCK to turn off the phone field for some roles, so the value isn't submitted.

I imagine the patch remains similar to the one already attached, and it needs to be applied as this causes complete breakage on Postgres in the mentioned circumstances.

neilnz’s picture

Category: support » bug
darrellduane’s picture

StatusFileSize
new187 bytes

I agree. Adding on to request this change be made.
I can't load data that I've exported because of this constraint. c: Here is a patch file for 6.x version

drewish’s picture

Status: Active » Needs review

Do we need an update function to change this on existing fields?

neilnz’s picture

Yes that's probably a good idea. Would anyone like to re-craft the patch? I can if noone else wants to.

Steve Dondley’s picture

+1

This issue causes a problem with node profile module when hiding the phone on the registration field: http://drupal.org/node/514080

uomeds’s picture

I am using the phone cck in advanced profile kit but the field is not visible upon registration. Nonetheless, when new users sign up, they are greeted with this error message.

    * user warning: Column 'field_phone_ottawa_value' cannot be null query: INSERT INTO content_field_phone_ottawa (vid, nid, delta, field_phone_ottawa_value) VALUES (15, 15, 0, NULL) in /home/uomeds/public_html/sites/all/modules/cck/content.module on line 1213.

I patched not null TRUE to FALSE. But it didn't help existing fields. I just tried deleting all the phone fields and re-creating them and it seems to work now.

thierry_gd’s picture

Status: Needs review » Fixed

Taken into account in 6.2.9 version

DanielJohnston’s picture

Version: 6.x-2.8 » 6.x-2.9
Status: Fixed » Active

I'm getting the following when saving a node with no content in the phone field:

user warning: Column 'field_phonenumber_value' cannot be null query: INSERT INTO content_field_phonenumber (vid, nid, field_phonenumber_value) VALUES (107, 95, NULL) in /srv/welfaretowork.co.uk/public/htdocs/sites/all/modules/cck/content.module on line 1213.

Suspect this bug may still be alive?

DanielJohnston’s picture

Oops. Forgot to mention I'm using latest versions of all modules, including Phone (CCK) 6.x-2.9

DanielJohnston’s picture

Version: 6.x-2.9 » 6.x-2.8
Status: Active » Fixed

Update - I've fixed the problem by removing then readding the offending field. No idea what went wrong the first time round. Apologies for the trouble...

jrefano’s picture

Looks like this bug still exists. I just updated from 2.8 to 2.9 and my phone fields would throw the following error

user warning: Column 'field_phone_value' cannot be null query: INSERT INTO content_type_personnel (vid, nid, field_title_value, field_phone_value, field_email_email, field_personnel_photo_fid, field_personnel_photo_list, field_personnel_photo_data) VALUES (250, 250, 'Dramaturg', NULL, NULL, NULL, NULL, NULL) in /Users/john/canary/wilma/sites/all/modules/cck/content.module on line 1213.

I had to delete the field and re-create. I think the new version just needs to run an update on the existing fields to make them accept null values.

jrefano’s picture

Version: 6.x-2.8 » 6.x-2.9
Status: Fixed » Active

Forgot to make it active

akolahi’s picture

I upgraded from 2.8 to 2.9 and I am also getting the user warning 'cannot be null'.

nathaniel’s picture

A query needs to be run to update all old phone fields. I only had one so I jumped in the database and changed it manually. Set Null to Yes Null and everything works swimmingly.

ALTER TABLE `content_type_event` CHANGE `field_event_phone_value` `field_event_phone_value` VARCHAR( 255 ) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL  
thierry_gd’s picture

Status: Active » Fixed

Fixed in 6.2.10 release

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.