Hello,

I have a fatal error during install (I tried twice) due to the missing table "user__allowed_languages" :

The website encountered an unexpected error. Please try again later.
User error: Drupal\Core\Database\DatabaseExceptionWrapper thrown while calling __toString on a Drupal\Core\StringTranslation\TranslatableMarkup object in /var/www/html/mysite-d8/web/core/lib/Drupal/Core/Database/Connection.php on line 686: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'mysite.user__allowed_languages' doesn't exist

I guess that during the installation, Allowed Languages module has to create this table and thus should not rise this error. My website has the right to create tables in MySQL, so I guess there is not environement reason that this missing table is not created. Actually, seeing source code of the module, I don't see what lines of code create the table ?

This problem may be due to the release of 18 March 2019 because I had tested the module a few weeks ago and he worked perfectly.

Thanks for your answer and your work !

Comments

Salvor_Hardin created an issue. See original summary.

nterbogt’s picture

Status: Active » Postponed (maintainer needs more info)

Are you able to provide more information like which URL you were using when you saw the error? What actions you were performing?

I've installed the module on a clean site through both drush and the UI and am unable to replicate it.

Thanks.

salvor_hardin’s picture

It was during the installation (composer then UI)

salvor_hardin’s picture

Issue summary: View changes
wwwahe’s picture

Same here while installing the module :

 PHP Fatal error:  Drupal\Core\Database\DatabaseExceptionWrapper thrown while calling __toString on a Drupal\Core\StringTranslation\TranslatableMarkup object in /var/www/d8/web/core/lib/Drupal/Core/Database/Connection.php on line 686: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'pj_d8.user__allowed_languages' doesn't exist: SELECT t.*
FROM
{user__allowed_languages} t
WHERE (entity_id IN (:db_condition_placeholder_0)) AND (deleted = :db_condition_placeholder_1) AND (langcode IN (:db_condition_placeholder_2, :db_condition_placeholder_3, :db_condition_placeholder_4, :db_condition_placeholder_5, :db_condition_placeholder_6, :db_condition_placeholder_7, :db_condition_placeholder_8, :db_condition_placeholder_9, :db_condition_placeholder_10, :db_condition_placeholder_11, :db_condition_placeholder_12, :db_condition_placeholder_13, :db_condition_placeholder_14))
ORDER BY delta ASC; Array
(
    [:db_condition_placeholder_0] => 1
    [:db_condition_placeholder_1] => 0
    [:db_condition_placeholder_2] =>  in /var/www/d8/web/core/lib/Drupal/Component/Utility/ToStringTrait.php on line 20
wwwahe’s picture

The module seems to install only if the default language is 'en'

nterbogt’s picture

Status: Postponed (maintainer needs more info) » Needs work

Thank you for the update. I'll investigate further and see where we are having issue.

nterbogt’s picture

Status: Needs work » Postponed (maintainer needs more info)

I've tested this:
* as a clean install on 'en' site.
* as a clean install on 'es' site.
* as an uninstall/reinstall on both the of the above.

I'm yet to encounter the issue. I need someone experiencing the issue to replicate and investigate.

rob230’s picture

This is so strange because I got the same problem when I installed the module (also when using a non-default language as the interface language). But then I couldn't get it to happen again, even after uninstalling the module and clearing the caches and running cron. Every subsequent attempt to install the module in any language succeeded and the table was created.

I think the error might be because the entity updates haven't been run, so the new table hasn't been created yet. But I don't know why sometimes it does create it and sometimes it doesn't.

I've attached a patch which causes the entity updates to be run after install, but I can't be 100% sure that it fixes the issue since I cannot get the issue to occur any more.

wwwahe’s picture

We still have this issue on new install.
The patch didn't solve the problem.

We need to create manually the table
I post here the query for people like me who get a broken website, so at least they could uninstall the module :

CREATE TABLE `user__allowed_languages` (
  `bundle` varchar(128) CHARACTER SET ascii NOT NULL DEFAULT '' COMMENT 'The field instance bundle to which this row belongs, used when deleting a field instance',
  `deleted` tinyint(4) NOT NULL DEFAULT '0' COMMENT 'A boolean indicating whether this data item has been deleted',
  `entity_id` int(10) unsigned NOT NULL COMMENT 'The entity id this data is attached to',
  `revision_id` int(10) unsigned NOT NULL COMMENT 'The entity revision id this data is attached to, which for an unversioned entity type is the same as the entity id',
  `langcode` varchar(32) CHARACTER SET ascii NOT NULL DEFAULT '' COMMENT 'The language code for this data item.',
  `delta` int(10) unsigned NOT NULL COMMENT 'The sequence number for this data item, used for multi-value fields',
  `allowed_languages_target_id` varchar(255) CHARACTER SET ascii NOT NULL COMMENT 'The ID of the target entity.',
  PRIMARY KEY (`entity_id`,`deleted`,`delta`,`langcode`),
  KEY `bundle` (`bundle`),
  KEY `revision_id` (`revision_id`),
  KEY `allowed_languages_target_id` (`allowed_languages_target_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='Data storage for user field allowed_languages.';

Regards

nterbogt’s picture

As with a number of you, I have run the install again and again... as english, spanish and french. Installing the module via the UI and drush and I just don't seem to be able to reproduce the error. I've rebuilt completely new docker environments to test it; and still can't reproduce the error.

If someone could screen capture the process they use to throw the error, I would love to see it.

My best guess is that it's a problem with specific implementations where Drupal fails to create the database table on install. This isn't necessarily _this_ modules issue and could be caused by any number of other modules that hook into the install process.

If anyone on here can reproduce the issue consistently... could I please get a copy of your composer.json? Could you also see if you can reproduce the issue with just drupal core and allowed languages... nothing else installed or available?

dromansab’s picture

StatusFileSize
new235.45 KB

Hi,

I can reproduce the error with Drupal 9. Table is not created and the patch does not work.

I created the table manually (as wwwahe recommends). The crash disappears but the error is still displayed at Status report page:

ENTITY/FIELD DEFINITIONS
Mismatched entity and/or field definitions
The following changes were detected in the entity type and field definitions.
User: The Allowed languages field needs to be installed.

Regards,
Dani

dromansab’s picture

StatusFileSize
new21.86 KB
kriboogh’s picture

I was having a similar problem with a custom module I'm writing, that also updates the user entity with a base field that has cardinality set to -1.

This is how I solved it: (replace with your module, and with your field)

/**
* Implements hook_module_preinstall().
*
* When updating the existing User entity with new base fields having
* cardinality of -1 (unlimited), it's upto the entityDefinitionUpdateManager
* to create the dedicated table. This however happens to late in the module
* install process done by the ModuleInstaller.
*
* This is only exceptionally the case when extending the user entity.
*
* When the entitytypemanager is called for fetching the field definitions,
* deeper down the line a cache id is generated with the current user. This
* cache id creation triggers the fielddefinitions of the user entity type to
* be collected, but at this stage, although the definitions are updated, the
* database is not. The following load on the entity storage of user, causes
* the map data to entity call to fail since it tries to find the dedicated
* table.
*
* To solve this, we need to create the database before the module intaller
* loops over all entity definitions.
*/
function _module_preinstall($module) {
if ($module == '') {

/** @var \Drupal\Core\Entity\EntityFieldManagerInterface $entity_field_manager */
$entity_field_manager = \Drupal::service('entity_field.manager');
$update_manager = \Drupal::entityDefinitionUpdateManager();
$entity_type_manager = \Drupal::entityTypeManager();

$entity_type_manager->clearCachedDefinitions();
$entity_type = $entity_type_manager->getDefinition('user');
$definitions = $entity_field_manager->getFieldStorageDefinitions($entity_type->id());

// You should do this for all your new custom fields.
$field_name = "";
$update_manager->installFieldStorageDefinition(field_name, $entity_type->id(), $module, $definitions[$field_name]);
}
}

ricky.bertram’s picture

#14 Worked like a charm for me, thank you!

grimal’s picture

Same problem here with 2.x, no table and "Mismatched entity and/or field definitions" after table creation.

I've manually created the table as #10, then uninstalled the module and re-enabled it to fix the "Mismatched entity" error.

bingol@ciandt.com’s picture

StatusFileSize
new2.39 KB
heddn’s picture

Version: 8.x-1.2 » 2.x-dev

Are there any recent reports of this on the 2.x branch?

kwolford121’s picture

If I download and enable version 2.0.0, then navigate to `/admin/people`, I get the error message below (I removed my database name since it wasn't relevant). It seems the table isn't created when the module is installed -- `allowed_languages.module` is empty. After applying the code in patch #17 to that file, then the module works fine.

I'm on Drupal 10.3.10 and PHP 8.1.13, by the way. (Please let me know if any more information would be helpful.)

The error on my site:

The website encountered an unexpected error. Try again later.

Drupal\Core\Database\DatabaseExceptionWrapper: Exception in People[user_admin_people]: SQLSTATE[42S02]: Base table or view not found: 1146 Table '<my_db_name>.user__allowed_languages' doesn't exist: SELECT "t".* FROM "user__allowed_languages" "t" WHERE ("entity_id" IN (:db_condition_placeholder_0, :db_condition_placeholder_1, :db_condition_placeholder_2, :db_condition_placeholder_3, :db_condition_placeholder_4)) AND ("deleted" = :db_condition_placeholder_5) AND ("langcode" IN (:db_condition_placeholder_6, :db_condition_placeholder_7, :db_condition_placeholder_8, :db_condition_placeholder_9)) ORDER BY "delta" ASC; Array ( [:db_condition_placeholder_0] => 1 [:db_condition_placeholder_1] => 2 [:db_condition_placeholder_2] => 3 [:db_condition_placeholder_3] => 4 [:db_condition_placeholder_4] => 6 [:db_condition_placeholder_5] => 0 [:db_condition_placeholder_6] => en [:db_condition_placeholder_7] => fr [:db_condition_placeholder_8] => und [:db_condition_placeholder_9] => zxx ) in main() (line 19 of index.php).