What may cause Column not found (nid) in on clause?

I’m using Drupal 7.14 and Entity API and Reference 1.0-rc3.

And I’m also using i18n, entityreference (not References) and field_sql_storage.

I get this error when saving a node that has some custom fields using references.

PDOException: SQLSTATE[42S22]: Column not found: 1054 Unknown column
‘field_data_body0.nid’ in ‘on clause’: SELECT
field_data_body0.entity_type AS entity_type,
field_data_body0.entity_id AS entity_id, field_data_body0.revision_id
AS revision_id, field_data_body0.bundle AS bundle FROM
{field_data_body} field_data_body0 INNER JOIN {node} node ON
field_data_body0.nid = node.nid WHERE (field_data_body0.deleted =
:db_condition_placeholder_0) AND (field_data_body0.entity_type =
:db_condition_placeholder_1) AND (field_data_body0.bundle IN
(:db_condition_placeholder_2, :db_condition_placeholder_3)) AND
(field_data_body0.entity_id IN (:db_condition_placeholder_4)) AND
(node.language IN (:db_condition_placeholder_5,
:db_condition_placeholder_6)) ORDER BY field_data_body0.body_value
ASC; Array ( [:db_condition_placeholder_0] => 0
[:db_condition_placeholder_1] => node [:db_condition_placeholder_2] =>
news [:db_condition_placeholder_3] => page
[:db_condition_placeholder_4] => 25 [:db_condition_placeholder_5] =>
it [:db_condition_placeholder_6] => und ) in
field_sql_storage_field_storage_query() (linea 577 di
/home/morpheu5/web/xdatanet/modules/field/modules/field_sql_storage/field_sql_storage.module).

What bothers me is that, first of all there’s a zero appended to the name of the table, and second, if I add that nid column to that table, Drupal is happy and everything seems to work.

I suspect there must have been some update gone horribly wrong, since maintenance is not under my control, and I had to implement some new features working on my local copy which at that time was already completely out of sync with the client’s staging and production servers.

I tried a number of patches, and I’ve gone through the code myself but I’m not this familiar with Drupal.

EDIT

It seems the nid column is getting added at some point in function preExecute in includes/database/select.inc specifically at row 1236

drupal_alter($hooks, $query);

the hooks acting here are

  • query
  • query_entity_field_access
  • query_node_access
  • query_entityreference

but after a hour long investigation I only came up with a huge headache, and I’m still not sure if I actually found and debugged all of those hooks. As far as I could see, the nid column is not present before the drupal_alter call while it is after, but it’s there at the beginning of each hook_query_TAG_alter I was able to find.

I must be missing something.

EDIT 2

The culprit seems to be i18n, specifically i18n_select, more specifically at row 137 of i18n_select.module where it adds the nid column.

EDIT 3

There, I opened a bug: https://drupal.org/node/1679646

Sponsored by SupremePR
This article was republished from its original source.
Call Us: 1(800)730-2416

Pixeldust is a 20-year-old web development agency specializing in Drupal and WordPress and working with clients all over the country. With our best in class capabilities, we work with small businesses and fortune 500 companies alike. Give us a call at 1(800)730-2416 and let’s talk about your project.

FREE Drupal SEO Audit

Test your site below to see which issues need to be fixed. We will fix them and optimize your Drupal site 100% for Google and Bing. (Allow 30-60 seconds to gather data.)

Powered by

What may cause Column not found (nid) in on clause?

On-Site Drupal SEO Master Setup

We make sure your site is 100% optimized (and stays that way) for the best SEO results.

With Pixeldust On-site (or On-page) SEO we make changes to your site’s structure and performance to make it easier for search engines to see and understand your site’s content. Search engines use algorithms to rank sites by degrees of relevance. Our on-site optimization ensures your site is configured to provide information in a way that meets Google and Bing standards for optimal indexing.

This service includes:

  • Pathauto install and configuration for SEO-friendly URLs.
  • Meta Tags install and configuration with dynamic tokens for meta titles and descriptions for all content types.
  • Install and fix all issues on the SEO checklist module.
  • Install and configure XML sitemap module and submit sitemaps.
  • Install and configure Google Analytics Module.
  • Install and configure Yoast.
  • Install and configure the Advanced Aggregation module to improve performance by minifying and merging CSS and JS.
  • Install and configure Schema.org Metatag.
  • Configure robots.txt.
  • Google Search Console setup snd configuration.
  • Find & Fix H1 tags.
  • Find and fix duplicate/missing meta descriptions.
  • Find and fix duplicate title tags.
  • Improve title, meta tags, and site descriptions.
  • Optimize images for better search engine optimization. Automate where possible.
  • Find and fix the missing alt and title tag for all images. Automate where possible.
  • The project takes 1 week to complete.