SQLSTATE[42S22]: Column not found: 1054 Unknown column *_target_id_int in on clause

Created on 22 May 2019, over 5 years ago
Updated 8 July 2023, over 1 year ago

Brand new DER field on User entity doesn't work in views relationships.

Here's the full message:

Error message
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'user__field_subscriptions.field_subscriptions_target_id_int' in 'on clause': SELECT users_field_data.uid AS uid, node_field_data_user__field_subscriptions.nid AS node_field_data_user__field_subscriptions_nid, taxonomy_term_field_data_user__field_subscriptions.tid AS taxonomy_term_field_data_user__field_subscriptions_tid FROM {users_field_data} users_field_data LEFT JOIN {user__field_subscriptions} user__field_subscriptions ON users_field_data.uid = user__field_subscriptions.entity_id AND user__field_subscriptions.deleted = :views_join_condition_0 INNER JOIN {node_field_data} node_field_data_user__field_subscriptions ON user__field_subscriptions.field_subscriptions_target_id_int = node_field_data_user__field_subscriptions.nid AND user__field_subscriptions.field_subscriptions_target_type = :views_join_condition_1 LEFT JOIN {taxonomy_term_field_data} taxonomy_term_field_data_user__field_subscriptions ON user__field_subscriptions.field_subscriptions_target_id_int = taxonomy_term_field_data_user__field_subscriptions.tid AND user__field_subscriptions.field_subscriptions_target_type = :views_join_condition_2 WHERE users_field_data.status = :db_condition_placeholder_3 LIMIT 11 OFFSET 0; Array ( [:db_condition_placeholder_3] => 1 [:views_join_condition_0] => 0 [:views_join_condition_1] => node [:views_join_condition_2] => taxonomy_term )

Attaching view definition yml.

The field "field_subscriptions" is set to reference taxonomy and content (nodes).
But the column "field_subscriptions_target_id_int" doesn't exist in the database - why wasn't it created when I created the field?
Why is it being queried?

πŸ› Bug report
Status

Fixed

Version

4.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States AaronBauman Philadelphia

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.

  • πŸ‡ͺπŸ‡ΈSpain cimo75

    Very same issue here.

  • πŸ‡©πŸ‡ͺGermany stevieb

    I'm also seeing this on a few installs

  • πŸ‡ΊπŸ‡ΈUnited States TolstoyDotCom L.A.

    AFAICT, the table is created with the whatever_target_id_int column after you submit the form where you choose the field type and enter its name. Then, when you submit the next form (where you choose the referenced types and the cardinality), a schema change results in the table being dropped and then created again, this time without the whatever_target_id_int column. This is using version 4.x-dev of the module on D10.

  • πŸ‡©πŸ‡ͺGermany stevieb

    I'm seeing these errors on all my Drupal 10.1 updates

    I also tried the Sandbox Module and receive the errors on a fresh install with both 3 & 4 versions.

    to reproduce add sandbox with D10.1 & Dynamic Entity Reference
    Activate media Module
    add ref Field to Article type content type allowing Article and media image
    save field

    the error is there on both versions of the module for Drupal 10

  • πŸ‡¦πŸ‡ΊAustralia larowlan πŸ‡¦πŸ‡ΊπŸ.au GMT+10

    I wonder if this is because of the move to READ_COMMITTED isolation level in Drupal 10.1 not recognizing Views (not Drupal views, DB Views)

  • πŸ‡¦πŸ‡ΊAustralia larowlan πŸ‡¦πŸ‡ΊπŸ.au GMT+10
  • πŸ‡ΊπŸ‡ΈUnited States TolstoyDotCom L.A.

    The problem is with Drupal views: the module code expects those Drupal views to have access to the whatever_target_id_int field.

    If I create a field and then add a whatever_target_id_int column to the table manually, I can create a Drupal view without issue.

    I *could* create a patch to add that column, but it'd be better for a maintainer to weigh in about this.

  • πŸ‡¦πŸ‡ΊAustralia larowlan πŸ‡¦πŸ‡ΊπŸ.au GMT+10

    So the module does some gymnastics to support config and content entities in a single field.

    If you have both, we set the target ID as a string, but then use a DB trigger to keep an INT version in sync.

    And then views does some dancing around that.

    Can you share what your views data looks like for this error as well as your field definition?

    Something like

    drush php-eval "var_export(\Drupal::service('views.views_data')->get('YOUR TABLE NAME HERE'))";

  • πŸ‡ΊπŸ‡ΈUnited States TolstoyDotCom L.A.

    Before my last comment I created a field 'test' on Article nodes. I set the field to accept content, terms, and users. Then, because it didn't have the column, I ran this in the db: alter table node__field_test add column field_test_target_id_int int not null default 0; and likewise with node_revision__field_test.

    I then created a simple Drupal view to show Article nodes and added the 'test' field as one of the fields to show. That worked as expected. If I hadn't manually changed the db, I would have got the error in the first post here.

    Note also that any triggers weren't created, or they were created but got wiped out when node__field_test was dropped and then recreated.

    Due to all the "gymnastics" the module goes through, it'd be best if someone who's more familiar with it would weigh in. I'm also unsure on what is the expected setup: should it even have the field_test_target_id_int column? Was that being phased out but the Drupal views code just wasn't updated yet? Why did this stop working?

    If no maintainers are available then I guess I could look into the module later on.

  • πŸ‡¦πŸ‡ΊAustralia larowlan πŸ‡¦πŸ‡ΊπŸ.au GMT+10

    'if no maintainers are available' - this is my fourth comment on the issue so not sure what you're expecting there.

    I'll see if I can reproduce it.

  • πŸ‡¦πŸ‡ΊAustralia larowlan πŸ‡¦πŸ‡ΊπŸ.au GMT+10

    Confirmed this behaviour

    It also looks like the events don't fire on update either.

  • πŸ‡ΊπŸ‡ΈUnited States TolstoyDotCom L.A.

    Re the maintainers bit, I looked the first time not the second, so my bad. Let me know if you need help testing anything.

  • πŸ‡¨πŸ‡¦Canada jibran Toronto, Canada

    Moving to 4.x

  • Status changed to Needs review over 1 year ago
  • Open on Drupal.org β†’
    Core: 10.1.x + Environment: PHP 8.1 & MySQL 5.7
    last update over 1 year ago
    Waiting for branch to pass
  • πŸ‡¦πŸ‡ΊAustralia larowlan πŸ‡¦πŸ‡ΊπŸ.au GMT+10

    Wondering if this is all that's needed.

    In my testing, the column is added on create, but then the update event fires and core drops our column.

  • πŸ‡ΊπŸ‡ΈUnited States TolstoyDotCom L.A.

    I tested the change using a field 'newtest'. The tables node__field_newtest and node_revision__field_newtest had field_newtest_target_id_int columns after the first screen and after the last. I was able to reference a user and a node from that field. I created a Drupal view as I described before and there aren't any warnings. It seems to work now.

  • Status changed to Needs work over 1 year ago
  • πŸ‡¨πŸ‡¦Canada jibran Toronto, Canada

    I suspected that 4.x HEAD was failing because of this bug but if #19 is fixing the bug here then we need to investigate the HEAD fails separately but meanwhile let's add test for this bug.

  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 10.1.x + Environment: PHP 8.1 & MySQL 5.7
    last update over 1 year ago
    72 pass
  • πŸ‡¨πŸ‡¦Canada jibran Toronto, Canada

    HEAD is green now and so is the patch. Let's add some tests.

  • Status changed to Needs review over 1 year ago
  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 10.1.x + Environment: PHP 8.1 & MySQL 5.7
    last update over 1 year ago
    62 pass, 6 fail
  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 10.1.x + Environment: PHP 8.1 & MySQL 5.7
    last update over 1 year ago
    62 pass, 6 fail
  • πŸ‡¦πŸ‡ΊAustralia larowlan πŸ‡¦πŸ‡ΊπŸ.au GMT+10

    Here's a test

  • Status changed to Needs work over 1 year ago
  • πŸ‡¦πŸ‡ΊAustralia larowlan πŸ‡¦πŸ‡ΊπŸ.au GMT+10

    Hmm these pass/fail locally for me on 11.x - thoughts @jibran?

  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 10.1.x + Environment: PHP 8.1 & MySQL 5.7
    last update over 1 year ago
    64 pass, 2 fail
  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 10.1.x + Environment: PHP 8.1 & MySQL 5.7
    last update over 1 year ago
    72 pass
  • Status changed to RTBC over 1 year ago
  • πŸ‡¨πŸ‡¦Canada jibran Toronto, Canada

    Sorry, I messed up the version check in one of the test fix but it is fixed now.

  • Status changed to Fixed over 1 year ago
  • πŸ‡¨πŸ‡¦Canada jibran Toronto, Canada

    Committed and pushed to 4.x. Thanks!

  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024