Table 'language_hierarchy_priority' already exists.

Created on 23 October 2024, 2 months ago

Problem/Motivation

During my deployment, just at the end of the updb execution and when starting the config import I get the error log "Table 'language_hierarchy_priority' already exists."

Steps to reproduce

On an existing website. Activate a new language and enable the module "language_hierarchy" with some priority already defined.

You should launch the command as follow: 'drush cr && drush updb -y && drush cim -y'

Proposed resolution

In the .install file the schema is declared and there is also a first update hook... Both are declaring the DB schema for the new table...
First question, do we really need the update hook? It looks like the hook_schema is enough.

If this hook_update_xxxx is really necessary than we should check if the table already exist

🐛 Bug report
Status

Active

Version

2.0

Component

Code

Created by

🇨🇭Switzerland redzeuf Geneva

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @redzeuf
  • 🇨🇭Switzerland redzeuf Geneva

    First patch to simply remove the hook_update_xxxx function.

  • 🇨🇭Switzerland redzeuf Geneva

    Second patch, just checking in the hook_update_xxxx if the table exist before creating it.
    If the table exist we don't try to create it.

  • 🇬🇧United Kingdom james.williams

    The update hook is for sites that had language hierarchy installed from before the schema hook existed. New installations of the module would not run the update hook. If you already had the table on installing the module, or on updating it, I imagine perhaps your database got into an unsupported state somehow? Did something interrupt its installation at some point perhaps, or reset its record of its schema / last installed version?

    https://www.drupal.org/docs/drupal-apis/update-api/updating-database-sch... is the most up-to-date documentation I can find; that shows how both of the hooks are necessary. Update hooks aren't usually designed to be safely run more than once, but of course if you got into this situation, I can understand how your fix would be necessary.

    So I'm closing this issue as works as designed, but I'm happy to continue dialog here if you can provide more detailed clearly repeatable steps with a fresh install? (I just tested your steps to reproduce on simplytest.me, using the browser equivalents for running updates, and could not reproduce the error.)

Production build 0.71.5 2024