Data fix: Field [field] refers to nonexistent entity type [type].

Last updated on
8 October 2021

Drupal 7 will no longer be supported after January 5, 2025. Learn more and find resources for Drupal 7 sites

Warning: This is a dangerous edit to make for some modules because you'll end up with a partially uninstalled module with no way to finish the uninstall and then your database will be out of shape and you'll need to repair it to recover your site. Instead of writing a custom uninstall process, you should re-download the module giving you the error and run the module uninstall.

This document describes how to fix a data issue if you see a watchdog message fitting the title, such as:

Field comment_body refers to nonexistent entity type comment.

The related issue for this is PHP 7.4 warnings with disabled Comment module.

Cause

This message is caused by a module not completely cleaning itself up after removal, or by disabling a module while its fields are in use. Specifically, a field instance exists that points to an entity type that no longer exists.

Data Fix

A way to fix this issue is to remove the field instance that is no longer valid.

Use the Devel module, go to /devel/php, and run the following code, setting $field_name and $entity to the values seen in your error message:

$field_name = 'comment_body';
$entity = 'comment';

$instances = field_read_instances(array('field_name' => $field_name, 'entity_type' => $entity), array('include_inactive' => TRUE));
if (!empty($instances)) {
  foreach ($instances as $instance) {
    field_delete_instance($instance, TRUE);
  }
}

The code will delete the field instance, and then if this was the last instance of the field, that field will also be deleted.

Help improve this page

Page status: No known problems

You can: