Great work guys.
Integrity constraint violation: 1048 Column 'tid' cannot be null'
#1 /var/www/drupal7/includes/database/database.inc(651): DatabaseStatementBase->execute(Array, Array)
#2 /var/www/drupal7/includes/database/mysql/query.inc(36): DatabaseConnection->query('INSERT INTO {ta...', Array, Array)
#3 /var/www/drupal7/sites/all/modules/taxonomy_entity_index/taxonomy_entity_index.module(155): InsertQuery_mysql->execute()
| Comment | File | Size | Author |
|---|---|---|---|
| #6 | what_if_there_are_no-1194076-6.patch | 1.09 KB | gadaniels72 |
Comments
Comment #1
dave reidHrm, I tested this thoroughly with nodes without terms and never encountered this. This sounds like something has a record for the field data, but not actually matched with a term? Maybe provide more details on how to replicate this with just core + taxonomy_entity_index enabled?
Comment #2
matslats commentedOk I'm not getting this any more.
Must have been something in my code.
Sorry for putting you to trouble.
Comment #3
matslats commentedIt happened again!
When an entity form is submitted, it is built in the submit handler. A non-required vocabulary with no terms submitted will put this in the entity:
And your function taxonomy_entity_index_field_attach_update assumes that every term in 'und' has a tid. This might be a core bug, but you can work around it easily, depending on whether you would write a row when there are no terms.
Comment #4
dave reidI am still not able to duplicate this. I added a new content type + taxonomy field using select widget. Submitting the node both with nothing selected or '- None -' selected still had an empty array in $node->field_tags.
Comment #5
dave reidComment #6
gadaniels72 commentedI realize that this is 6 years old, but I ran into the same issue implementing this module this week against a custom entity. What happens is more of a data issue on the entity really than necessarily a problem with this module.
It happens where there is a record in the entity's taxonomy field but the term ID is null. For example, I have an entity ('entity') that has 2 fields that use a problem taxonomy stored in field_term. When I ran the index tool, it threw the same error. Further researching my database, there is an actual entry in the field_data_field_term with a field_term_tid value of null. This breaks the indexing tool.
My solution was to add a check in the module so that it ignores any terms where the term ID is null and does not enter them in the taxonomy_entity_index table. This allowed me to successfully index our taxonomy terms on a custom entity.
This is the actual error being thrown from the log files:
PDOException: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'tid' cannot be null: INSERT INTO {taxonomy_entity_index} (entity_type, bundle, entity_id, revision_id, field_name, delta, tid) 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] => entity [:db_insert_placeholder_1] => entity [:db_insert_placeholder_2] => 225956 [:db_insert_placeholder_3] => 225956 [:db_insert_placeholder_4] => field_triage_problem_history [:db_insert_placeholder_5] => 0 [:db_insert_placeholder_6] => ) in taxonomy_entity_index_field_attach_update()Comment #7
cameron prince commented