When I try to create and save a new node of a custom content type, it fails with errors like this, for every integer field type including lists:

PDOException: SQLSTATE[HY000]: General error: 1366 Incorrect integer value: '' for column 'field_fieldname_value' at row 1: INSERT INTO {field_fieldname} (entity_type, revision_id, bundle, delta, language, field_fieldname_value) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3, :db_insert_placeholder_4, :db_insert_placeholder_5, :db_insert_placeholder_6); Array ( [:db_insert_placeholder_0] => node [:db_insert_placeholder_1] => 2277 [:db_insert_placeholder_2] => 2277 [:db_insert_placeholder_3] => ctype1 [:db_insert_placeholder_4] => 0 [:db_insert_placeholder_5] => und [:db_insert_placeholder_6] => ) in field_sql_storage_field_storage_write() line 424 of /path/to/drupal/modules/field/modules/field_sql_storage/field_sql_storage.module).

The website encountered an unexpected error. Please try again later.

This should not happen for most of the fields as they are not defined as being required. Would guess the last item in the code dumped above should be a NULL rather than a blank.

Background: I am migrating a site from older Drupal. The migrated nodes are fine without any value in these fields, but cannot create any new nodes without filling in some value for every one of these fields. Which is a problem as sometimes the value is unknown but not essential.

Comments

leeksoup’s picture

Project: Drupal core » Content Construction Kit (CCK)
Version: 7.7 » 7.x-2.x-dev
Component: field system » upgrade path

I tried creating a brand new blank test site and there I do not have the problem. The original site with the problem was migrated from D6, so my new guess is the problem was introduced in the migration.

Looking at the field_config_instance DB tables, there seems a difference between the way default_value for the two fields is stored. (I set no default value for either one.) I don't know enough about the tables to really figure it out, but the new field has like this:
... \"default_value\";N; ...

but the old one doesn't has the N. It looks like:
... \"default_value\";a:1:{i:0;a:1:{s:5:\"value\";s:0:\"\";}} ...

Is this significant? What does the N mean?

leeksoup’s picture

Did some digging around the drupal website and found out the function to print the field config instance values. Using it from devel, like so:

print_r (field_read_instances());

I find out that the migrated integer field have array for default_value, like this:

[default_value] => Array
                (
                    [0] => Array
                        (
                            [value] => 
                        )

                )

but newly created field have a single value, like this:

            [default_value] => 
            [id] => 9

Seem like this might be the problem?

I am willing to test a fix if you can tell me what to try.

leeksoup’s picture

Title: Integer fields always require value, even when field is not required for content type » migrate produces wrong default value, causes saving new nodes to fail
Priority: Normal » Major

OK, I did more digging and found out how to hack the data field in the SQL. If I change it into a single value (N) like the new field's, then the problem for saving new nodes without an entry in each integer field is resolved.

This shows that the problem with the migrated integer / number fields is that the default_value is made an array when it needs to be a single value.

Have changed priority to major as this will be a major problem when people try to add new nodes to migrated sites. I didn't see any issues in the queue that address this.

blasto333’s picture

Is this because mysql for drupal 7 is in strict mode?

drzraf’s picture

this seems to be a concerns for a bunch of fields.
Eg: an URL field where D6 default to Validate URL unchecked ends-up being convert to D7 with Validate URL checked.
I believe there are case where this could become a security issue when the behavior changes to what was requested by the admin to a more permissive value.

drzraf’s picture

referencing just fixed #1351880: List widgets without keys not reflected in field_data_* and field_revision_* tables so that it may give a hint about the what to look into content_migrate.module