Resolve the error that is raised on visit /admin/modules/uninstall:

The website encountered an unexpected error. Please try again later.</br></br><em class="placeholder">Drupal\Core\Database\DatabaseExceptionWrapper</em>: SQLSTATE[42S22]: Column not found: 1054 Unknown column &#039;unpublish_state&#039; in &#039;where clause&#039;: SELECT 1 AS expression
FROM
{node_field_data} t
WHERE unpublish_state IS NOT NULL
LIMIT 1 OFFSET 0; Array
(
)
 in <em class="placeholder">Drupal\Core\Entity\Sql\SqlContentEntityStorage-&gt;countFieldData()</em> (line <em class="placeholder">1805</em> of <em class="placeholder">core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php</em>). <pre class="backtrace">Drupal\Core\Database\Statement-&gt;execute(Array, Array) (Line: 631)
Drupal\Core\Database\Connection-&gt;query(&#039;SELECT 1 AS expression
FROM
{node_field_data} t
WHERE unpublish_state IS NOT NULL
LIMIT 1 OFFSET 0&#039;, Array, Array) (Line: 358)
Drupal\Core\Database\Driver\mysql\Connection-&gt;query(&#039;SELECT 1 AS expression
FROM
{node_field_data} t
WHERE unpublish_state IS NOT NULL
LIMIT 1 OFFSET 0&#039;, Array, Array) (Line: 510)
Drupal\Core\Database\Query\Select-&gt;execute() (Line: 1805)
Drupal\Core\Entity\Sql\SqlContentEntityStorage-&gt;countFieldData(Object, 1) (Line: 64)
Drupal\taxonomy_term_depth\DepthUninstallValidator-&gt;validate(&#039;scheduler_content_moderation_integration&#039;) (Line: 573)
Drupal\Core\Extension\ModuleInstaller-&gt;validateUninstall(Array) (Line: 99)
Drupal\Core\ProxyClass\Extension\ModuleInstaller-&gt;validateUninstall(Array) (Line: 121)
Drupal\system\Form\ModulesUninstallForm-&gt;buildForm(Array, Object)
call_user_func_array(Array, Array) (Line: 519)
Drupal\Core\Form\FormBuilder-&gt;retrieveForm(&#039;system_modules_uninstall&#039;, Object) (Line: 276)
Drupal\Core\Form\FormBuilder-&gt;buildForm(Object, Object) (Line: 93)
Drupal\Core\Controller\FormController-&gt;getContentResult(Object, Object)
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber-&gt;Drupal\Core\EventSubscriber\{closure}() (Line: 582)
Drupal\Core\Render\Renderer-&gt;executeInRenderContext(Object, Object) (Line: 124)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber-&gt;wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber-&gt;Drupal\Core\EventSubscriber\{closure}() (Line: 151)
Symfony\Component\HttpKernel\HttpKernel-&gt;handleRaw(Object, 1) (Line: 68)
Symfony\Component\HttpKernel\HttpKernel-&gt;handle(Object, 1, 1) (Line: 57)
Drupal\Core\StackMiddleware\Session-&gt;handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\KernelPreHandle-&gt;handle(Object, 1, 1) (Line: 106)
Drupal\page_cache\StackMiddleware\PageCache-&gt;pass(Object, 1, 1) (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache-&gt;handle(Object, 1, 1) (Line: 115)
Drupal\shield\ShieldMiddleware-&gt;handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware-&gt;handle(Object, 1, 1) (Line: 52)
Drupal\Core\StackMiddleware\NegotiationMiddleware-&gt;handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel-&gt;handle(Object, 1, 1) (Line: 693)
Drupal\Core\DrupalKernel-&gt;handle(Object) (Line: 19)

Comments

vuil created an issue. See original summary.

vuil’s picture

Issue summary: View changes

I update the issue summary.

vuil’s picture

Status: Active » Needs review

I see that there is not in DB -> {node_field_data} column {unpublish_state}.

I remove the module codebase and exclude the module from config, core.extensions.yml.
And, now it works well.

vuil’s picture

Status: Needs review » Fixed

The issue is private case, and it is coming from not very well, DB lock, on installing. And there is a missing column `unpublish_state` in DB node_field_data table. The issue is fixed manually.

Status: Fixed » Closed (fixed)

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

mstrelan’s picture

I had the same issue, where publish_state and unpublish_state were missing and the status report showed "Mismatched entity and/or field definitions".

I wrote this controller to fix it.

<?php

namespace Drupal\my_module\Controller;

use Drupal\Core\Controller\ControllerBase;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
 * Returns responses for my_module routes.
 */
class MyModuleController extends ControllerBase {

  /**
   * The entity definition update manager.
   *
   * @var \Drupal\Core\Entity\EntityDefinitionUpdateManagerInterface
   */
  protected $entityDefinitionUpdateManager;

  /**
   * The entity last installed schema repository.
   *
   * @var \Drupal\Core\Entity\EntityLastInstalledSchemaRepositoryInterface
   */
  protected $entityLastInstalledSchemaRepository;

  /**
   * The module handler.
   *
   * @var \Drupal\Core\Extension\ModuleHandlerInterface
   */
  protected $moduleHandler;

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container) {
    $instance = parent::create($container);
    $instance->entityDefinitionUpdateManager = $container->get('entity.definition_update_manager');
    $instance->entityLastInstalledSchemaRepository = $container->get('entity.last_installed_schema.repository');
    $instance->moduleHandler = $container->get('module_handler');
    return $instance;
  }

  /**
   * Fix schema after installing scheduler_content_moderation_integration.
   *
   * After enabling the module via config sync the publish_state and
   * unpublish_state fields were missing with no way to restore them and no way
   * to uninstall the module. This function installs the missing fields to allow
   * the module to be uninstalled.
   */
  public function fixSchedulerContentModerationIntegration() {
    $updated = FALSE;
    if ($this->moduleHandler->moduleExists('scheduler_content_moderation_integration')) {
      $entity_type = $this->entityDefinitionUpdateManager->getEntityType('node');
      $installed = $this->entityLastInstalledSchemaRepository->getLastInstalledFieldStorageDefinitions($entity_type->id());
      $definitions = scheduler_content_moderation_integration_entity_base_field_info($entity_type);
      foreach ($definitions as $field_name => $definition) {
        if (empty($installed[$field_name])) {
          $this->entityDefinitionUpdateManager->installFieldStorageDefinition($field_name, $entity_type->id(), 'scheduler_content_workbench_moderation_integration', $definition);
          $this->messenger()->addMessage($this->t('Field %field_name installed.', [
            '%field_name' => $field_name,
          ]));
          $updated = TRUE;
        }
      }
    }
    if (!$updated) {
      $this->messenger()->addMessage($this->t('No schema updates required.'));
    }
    return $this->redirect('system.status');
  }

}
vuil’s picture

Sound good!

Could you integrate it as an update_hook() function in the .module file?
Thank you.

Great work!

darktek’s picture

#6 worked for me very well.

In case someone doesn't know how to implement above's code, you can create an specific url path to run that code in your routing.yml file:

my_module.fix_scheduler_module:
  path: /admin/config/user-interface/fix-scheduler-module
  defaults:
    _title: 'Fix Scheduler module'
    _controller: '\Drupal\my_module_folder\Controller\MyModuleController::fixSchedulerContentModerationIntegration'
  requirements:
    _access: 'TRUE'
evgen’s picture