Problem/Motivation

I am creating migrations that use the local Drupal 8 site as the source (to convert image fields and other entities to media entities).

Accordingly, my migration's source is configured like this:

  source:
    # Use the site's own DB as the source.
    key: default
    target: default

However, when I run a migration command such as 'drush ms MYMIGRATION', I see this warning:

 [error]  Message: Failed to connect to your database server. The server reports the following
message: /No database connection configured for source plugin variable/.
 * Is the database server running?
 * Does the database exist, and have you entered the correct database name?
 * Have you entered the correct username and password?
 * Have you entered the correct database hostname?

This is caused by a combination of migrate's SqlBase source doing this:

  protected function setUpDatabase(array $database_info) {
    if (isset($database_info['key'])) {
      $key = $database_info['key'];
    }
    else {
      // If there is no explicit database configuration at all, fall back to a
      // connection named 'migrate'.
      $key = 'migrate';
    }

and a migration probably in migrate_drupal using the Drupal\migrate_drupal\Plugin\migrate\source\Variable plugin.

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

Issue fork drupal-3221087

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

joachim created an issue. See original summary.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

trackleft2’s picture

I think this issue also affects the concept of replacing the feeds module with migrate.

kunalkursija’s picture

+1 - I often get the error too during drush ms MIGRATION_ID and drush mim MIGRATION_ID, Interesting thing is that even with the error the data gets migrated properly.

yivanov’s picture

I also confirm getting this error message while running migration from a CSV source (not even a database source). The migration itself executes correctly.
I've noticed that the Drupal\migrate\Plugin\migrate\source\SqlBase's checkRequirements() method is trying to get the migration DB connection for all migrate plugin definitions - and it happens after cache clear. I don't see any good way of handling this apart from providing fake migrate DB connection with the same credentials as the default DB just to make it suppress the error. But definitely this needs to be resolved properly.

kiseleva.t’s picture

Status: Active » Closed (duplicate)

It seems duplicated with https://www.drupal.org/project/drupal/issues/3198339.
Issue comes from migrate_drupal_migration_plugins_alter for system_site migration and variable source plugin.
It appears on other migrations due to load definition for migration plugins (usually after cache clear).

Patch provided to that issue - error moved to logs instead of printing in Drupal messages.

olarin’s picture

Status: Closed (duplicate) » Active

Having just run into this issue myself, I'm not convinced it should be marked as a duplicate of the error reporting issue; the patch on that issue would just sort of partially hide this problem, not solve it. It doesn't seem like the entire migrate system should always expect there to be a migration database keyed as "migrate" (or if it does, then at the very least, that should be better documented somewhere - several of the migration documentation pages show examples of database connection setups with a "migrate" key, but without any indication that that key is special or can't be changed out).

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.9 was released on December 7, 2022 and is the final full bugfix release for the Drupal 9.4.x series. Drupal 9.4.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.5.x-dev branch from now on, and new development or disruptive changes should be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

richardhobbs’s picture

I get the above error message when I do a drush cr followed by drush ms if I do drush ms again there is no error message until I do another drush cr

Drupal 10.3.10

Migrate Plus 6.0.5
Migrate Tools 6.0.5

pfrenssen’s picture

The error is originating from migrate_drupal_migration_plugins_alter() but should not be emitted. The code is doing a requirements check for migrating the "variables" subsystem, but this doesn't exist in Drupal 8+ since variables were replaced with config.

There is similar code just above that will suppress the exception for sites running Drupal 7+ which do not meet the requirements of the D6 taxonomy vocabulary migration:

    catch (RequirementsException $e) {
      // This code currently runs whenever the definitions are being loaded and
      // if you have a Drupal 7 source site then the requirements will not be
      // met for the d6_taxonomy_vocabulary migration.
    }

We can follow the same pattern, something like this:

    catch (RequirementsException $e) {
      // This code currently runs whenever the definitions are being loaded and
      // if you have a Drupal 8+ source site then the requirements will not be
      // met for the system_site migration since the 'variables' subsystem was
      // replaced with config entities in Drupal 8.
    }

pfrenssen’s picture

Title: fallback on 'migrate' as the database key causes error messages if migrations use a different source » Suppress error about missing requirements for migrating variables when using Drupal 8+ as a source

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.