When I tried to uninstall the module, I get this fun error:

In SqlContentEntityStorage.php line 1490:
                                                                                                                                                             
  Exception thrown while performing a schema update. SQLSTATE[42S22]: Column not found: 1054 Unknown column 'entity_table.id' in 'field list': INSERT INTO   
  {field_deleted_data_38d3088921} (bundle, entity_id, revision_id, langcode, created_value, deleted, delta) SELECT entity_table.contact_form AS bundle, ent  
  ity_table.id AS entity_id, entity_table.id AS revision_id, entity_table.langcode AS langcode, entity_table.created AS created_value, :deleted AS deleted,  
   :delta AS delta                                                                                                                                           
  FROM                                                                                                                                                       
  {contact_message} entity_table                                                                                                                             
  WHERE entity_table.created IS NOT NULL FOR UPDATE; Array                                                                                                   
  (                                                                                                                                                          
      [:deleted] => 1                                                                                                                                        
      [:delta] => 0                                                                                                                                          
  )                                                                                                                                                          
                                                                                                                                                             

In Connection.php line 686:
                                                                                                                                                             
  SQLSTATE[42S22]: Column not found: 1054 Unknown column 'entity_table.id' in 'field list': INSERT INTO {field_deleted_data_38d3088921} (bundle, entity_id,  
   revision_id, langcode, created_value, deleted, delta) SELECT entity_table.contact_form AS bundle, entity_table.id AS entity_id, entity_table.id AS revis  
  ion_id, entity_table.langcode AS langcode, entity_table.created AS created_value, :deleted AS deleted, :delta AS delta                                     
  FROM                                                                                                                                                       
  {contact_message} entity_table                                                                                                                             
  WHERE entity_table.created IS NOT NULL FOR UPDATE; Array                                                                                                   
  (                                                                                                                                                          
      [:deleted] => 1                                                                                                                                        
      [:delta] => 0                                                                                                                                          
  )                                                                                                                                                          
                                                                                                                                                             

In Statement.php line 59:
                                                                                            
  SQLSTATE[42S22]: Column not found: 1054 Unknown column 'entity_table.id' in 'field list'  

After some trial and error, I found if I truncate the contact_message table, I can then ununstall this module. Maybe something need to go in an uninstall hook to do as such?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

labboy0276 created an issue. See original summary.

mobius_time’s picture

I also receive an error when uninstalling the 8.x-1.0 version of this module:

drush pm-uninstall contact_storage

In Connection.php line 695:
                                                                               
  SQLSTATE[42S22]: Column not found: 1054 Unknown column 'id' in 'where claus  
  e': SELECT 1 AS expression                                                   
  FROM                                                                         
  {contact_message} t                                                          
  WHERE id IS NOT NULL                                                         
  LIMIT 1 OFFSET 0; Array                                                      
  (                                                                            
  )                                                                            
                                                                               

In Statement.php line 59:
                                                                               
  SQLSTATE[42S22]: Column not found: 1054 Unknown column 'id' in 'where clause'                                                                           
                                                                               

And then I get an error in the admin interface when I click on the Extend > Uninstall tab.

jacktonkin’s picture

I was getting the same errors as #2 above, and solved it by putting the following in an update function in a custom module:

module_load_install('contact_storage');
_contact_storage_ensure_fields();

This adds the missing id column and allows the module to uninstall cleanly.

jacktonkin’s picture

On closer inspection the code in #3 was only required to recover from the failed uninstall. Simply truncating the contact_message and contact_message__${field_name} tables was enough to perform the uninstall.

jacktonkin’s picture

Version: 8.x-1.0-beta9 » 8.x-1.0
Status: Active » Needs review
FileSize
650 bytes

The attached patch implements hook_uninstall to truncate all of the entity tables prior to removal.

Note that I haven't tested against the current release as I only have 8.x-1.0 installed.

afagioli’s picture

This was also breaking the site at send of personal contact form.

Here's how I fixed this:

* make a backup
* composer remove drupal/contact_storage
* drush --uri=https://site cr
* composer require drupal/contact_storage
* navigate a bit from admin/modules and admin/modules/uninstall back and forth (silly, eh?)
* uninstall module, now working

Hope this helps

urix’s picture

Hello.
I'm having the same error upon uninstallation of this module

Drupal\Core\Database\DatabaseExceptionWrapper: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'base_table.id' in 'field list': SELECT base_table.id AS id, base_table.id AS base_table_id FROM {contact_message} base_table LIMIT 1 OFFSET 0; Array ( ) in Drupal\Core\Entity\EntityStorageBase->hasData() (line 588 of /home/c/co43587/public_html/core/lib/Drupal/Core/Entity/EntityStorageBase.php).

Truncating tables contact_message and contact_message_{field_name} was not enough.
I see that there was no 'id' column in 'contact_message' table.
So, after manually adding this column, uninstallation was successful.

SamTheMan’s picture

The black magic in #6 solved it for me. Thanks @afagioli!

yi_jiang’s picture

have the same issue #7, its a pain.

hamadknows’s picture

+1 for #6, it works like a charm for me!
Thanks

filsterjisah’s picture

Same issue.

Since the issue is about uninstalling data backup (of contact_form entities) should not be needed.
The update hook I used to cleanly uninstall:

function MYMODULE_update_8001() {
  $storage = \Drupal::entityTypeManager()->getStorage('contact_form');
  $entities = $storage->loadMultiple();
  if ($entities) {
    $storage->delete($entities);
  }

  module_load_install('contact_storage');
  _contact_storage_ensure_fields();

  \Drupal::database()->truncate('contact_message')->execute();
}
eelkeblok’s picture

Status: Needs review » Closed (duplicate)
Related issues: +#3039906: Properly uninstall entity types

This and #3039906: Properly uninstall entity types are duplicates. This issue is a little older, but I think the direction the solution in the other ticket is taking is a bit more appropriate instead of having to "manually" truncate database tables.