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.
When submitting the node form, I've the following fatal error:
PDOException: SQLSTATE[22001]: String data, right truncated: 1406 Data too long for column 'field_contact_form_country_value' at row 1: INSERT INTO {field_data_field_contact_form_country} (entity_type, entity_id, revision_id, bundle, delta, language, field_contact_form_country_value, field_contact_form_country_format) 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, :db_insert_placeholder_7); Array ( [:db_insert_placeholder_0] => node [:db_insert_placeholder_1] => 4494 [:db_insert_placeholder_2] => 4776 [:db_insert_placeholder_3] => contact_form [:db_insert_placeholder_4] => 0 [:db_insert_placeholder_5] => und [:db_insert_placeholder_6] => All [:db_insert_placeholder_7] => ) in field_sql_storage_field_storage_write() (line 452 of modules/field/modules/field_sql_storage/field_sql_storage.module).
Executed code:
>=> class DatabaseStatementBase { public $dbh = class DatabaseConnection_mysql { protected $needsCleanup = FALSE; protected $target = 'default'; protected $key = 'default'; protected $logger = NULL; protected $transactionLayers = array (...); protected $driverClasses = array (...); protected $statementClass = 'DatabaseStatementBase'; protected $transactionSupport = TRUE; protected $transactionalDDLSupport = FALSE; protected $temporaryNameIndex = 0; protected $connectionOptions = array (...); protected $schema = class DatabaseSchema_mysql { ... }; protected $prefixes = array (...); protected $prefixSearch = array (...); protected $prefixReplace = array (...) }; public $queryString = 'INSERT INTO field_data_field_contact_form_country (entity_type, entity_id, revision_id, bundle, delta, language, field_contact_form_country_value, field_contact_form_country_format) 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, :db_insert_placeholder_7)' }
>=> class DatabaseStatementBase { public $dbh = class DatabaseConnection_mysql { protected $needsCleanup = FALSE; protected $target = 'default'; protected $key = 'default'; protected $logger = NULL; protected $transactionLayers = array (...); protected $driverClasses = array (...); protected $statementClass = 'DatabaseStatementBase'; protected $transactionSupport = TRUE; protected $transactionalDDLSupport = FALSE; protected $temporaryNameIndex = 0; protected $connectionOptions = array (...); protected $schema = class DatabaseSchema_mysql { ... }; protected $prefixes = array (...); protected $prefixSearch = array (...); protected $prefixReplace = array (...) }; public $queryString = 'INSERT INTO field_data_field_contact_form_country (entity_type, entity_id, revision_id, bundle, delta, language, field_contact_form_country_value, field_contact_form_country_format) 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, :db_insert_placeholder_7)' }
=> $stmt = class DatabaseStatementBase { public $dbh = class DatabaseConnection_mysql { protected $needsCleanup = FALSE; protected $target = 'default'; protected $key = 'default'; protected $logger = NULL; protected $transactionLayers = array (...); protected $driverClasses = array (...); protected $statementClass = 'DatabaseStatementBase'; protected $transactionSupport = TRUE; protected $transactionalDDLSupport = FALSE; protected $temporaryNameIndex = 0; protected $connectionOptions = array (...); protected $schema = class DatabaseSchema_mysql { ... }; protected $prefixes = array (...); protected $prefixSearch = array (...); protected $prefixReplace = array (...) }; public $queryString = 'INSERT INTO field_data_field_contact_form_country (entity_type, entity_id, revision_id, bundle, delta, language, field_contact_form_country_value, field_contact_form_country_format) 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, :db_insert_placeholder_7)' } includes/database/database.inc:679 2.0660 108926864 -> DatabaseStatementBase->execute($args = array (':db_insert_placeholder_0' => 'node', ':db_insert_placeholder_1' => '4494', ':db_insert_placeholder_2' => '4776', ':db_insert_placeholder_3' => 'contact_form', ':db_insert_placeholder_4' => 0, ':db_insert_placeholder_5' => 'und', ':db_insert_placeholder_6' => 'All', ':db_insert_placeholder_7' => NULL), $options = array ('target' => 'default', 'return' => 3, 'fetch' => 5, 'throw_exception' => TRUE)) includes/database/database.inc:680
Related issues:
#1015916: Image field "title" allows more data than database column size.
Field definition:
// Exported field_base: 'field_contact_form_country'
$field_bases['field_contact_form_country'] = array(
'active' => 1,
'cardinality' => 1,
'deleted' => 0,
'entity_types' => array(),
'field_name' => 'field_contact_form_country',
'foreign keys' => array(
'format' => array(
'columns' => array(
'format' => 'format',
),
'table' => 'filter_format',
),
),
'indexes' => array(
'format' => array(
0 => 'format',
),
),
'locked' => 0,
'module' => 'text',
'settings' => array(
'entity_translation_sync' => FALSE,
'max_length' => 2,
),
'translatable' => 0,
'type' => 'text',
);
Submit code looks like this:
function foo_contact_form_submit($form, $form_state) {
$node = node_form_submit_build_node($form, $form_state);
$node->field_contact_form_country[LANGUAGE_NONE][0]['value'] = foo_regional_get_current_country(); // which has the value: Array ( [und] => Array ( [0] => Array ( [value] => All ) ) )
node_save($node);
It is a bug?
Comments
Comment #0.0
kenorb CreditAttribution: kenorb commentedmore info
Comment #0.1
kenorb CreditAttribution: kenorb commentedcleaner code
Comment #1
kenorb CreditAttribution: kenorb commented