PDOException: SQLSTATE[42S22]: Column not found: 1054 Unknown column

Created on 6 March 2013, over 11 years ago
Updated 20 February 2024, 4 months ago

I'm running into a problem where I get PDOExceptions thrown about unknown collumns.

I did see a couple bug reports about it in the issue queue, but they were marked as fixed. If I've overlooked an existing ticket, please feel free to close this issue and send me to the duplicate.

Here's how I produced the error:
- A Drupal install with field translation, entityreference and multilingual select turned on.
- I have two content types, "news" and "news category".
- Both content types use field translation as provided by the entity translation module.
- Both content types have the title replaced by an actual field, using the title module.
- Both content types have a default language set to "dutch", this language cannot be changed once applied and the language neutral option is disabled.
- The "news" content_type contains 1 entity_reference field.
- The entity_reference field is not translated.
- The entity_reference field can only reference nodes of type "news_category".

Expected behavior:
- To be able to create news_category nodes and news nodes.
- To be able to select a news_category node using the entity_reference field on the news node form.
- Because both content_types use field translation, I expect the nid to remain the same across translations (This is how field_translation works, right?)
- Because the entity_reference field is set to be not translatable, nodes are related by nid, and nid's don't change amongst translations, the nodes should then be related across translations.

Actual behavior:
- The following error when viewing, creating or editing a node of content_type 'news':

PDOException: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'field_data_title_field0.nid' in 'on clause': SELECT DISTINCT field_data_title_field0.entity_type AS entity_type, field_data_title_field0.entity_id AS entity_id, field_data_title_field0.revision_id AS revision_id, field_data_title_field0.bundle AS bundle FROM {field_data_title_field} field_data_title_field0 INNER JOIN {node} node ON field_data_title_field0.nid = node.nid WHERE (field_data_title_field0.deleted = :db_condition_placeholder_0) AND (field_data_title_field0.entity_type = :db_condition_placeholder_1) AND (field_data_title_field0.bundle IN (:db_condition_placeholder_2)) AND (node.language IN (:db_condition_placeholder_3, :db_condition_placeholder_4)) ORDER BY field_data_title_field0.title_field_value ASC; Array ( [:db_condition_placeholder_0] => 0 [:db_condition_placeholder_1] => node [:db_condition_placeholder_2] => news_category [:db_condition_placeholder_3] => en [:db_condition_placeholder_4] => und ) in field_sql_storage_field_storage_query() (line 582 of /home/ruben/Eclipse Workspaces/Usendes/epst2/modules/field/modules/field_sql_storage/field_sql_storage.module).

I can spend a few hours trying to fix things, but I'm not familiar with either the source of either entity_translations or entityreference or even the entity API. So if anyone can point me in the right direction or if anyone knows a solution to this, any help is very much appreciated.

πŸ› Bug report
Status

Active

Version

1.0

Component

Documentation

Created by

πŸ‡³πŸ‡±Netherlands ruben_vreeken

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡­πŸ‡ΊHungary danyg Budapest

    My approach was here that the node.module's _node_query_node_access_alter() function has a bad assumption with the field. It assumes that field name to check is "nid" always. But if we use the entityreference module, the referenced field will be entity_id. So, my patch checks if the base_table contains "field_data_" or "field_revision_" string, the referencing field will be entity_id.
    I tried to catch the point where I'm able to alter the subquery in the scope of entityreference.module after the node.module adds the wrong query to it, but I wasn't able to do (since both have the same weight in the system table and entityreference's query alter executed earlier).
    So, it's not the perfect solution, but it fixed the unknown column issue for me.

Production build 0.69.0 2024