Drupal 8: Configuration Originates From A Different Site

One gotcha when importing configuration to a Drupal site can be a message that tells you that the configuration you are trying to import is from another site.

Here is the error that can be seen on the Configuration Synchronize page.

The staged configuration cannot be imported, because it originates from a different site than this site. You can only synchronize configuration between cloned instances of this site.

This error happens because the UUID of the site (in the database) is different to that in the configuration (in the code). The UUID in the code is stored in the configuration file system.site.yml. The reason for this check is to ensure that your don't destroy your Drupal site by installing configuration that was created from another site.

If the UUID doesn't match between the database and code then Drupal will refuse to accept it and will not import your config. This situation can arise from you installing a fresh copy of the site and needing to import your existing configuration over the top. As the site install generates a new UUID the two will be different and Drupal won't install your config.

There is a way around this, as long as you are sure this is what you want.

The easiest way to solve this is to overwrite the value in the configuration with the value in your database. The first step is to find out what the value is in your database by using Drush. The following command will print out your site UUID.

$ drush config-get "system.site" uuid
'system.site:uuid': d6eb07f8-16d0-4c62-8fac-7e1cc2cc7046

Using this you can then change the UUID at the top of the system.site.yml.

uuid: d6eb07f8-16d0-4c62-8fac-7e1cc2cc7046
name: 'My Awesome Drupal Website'
mail: [email protected]
slogan: 'Drupal site'
page:
  403: ''
  404: ''
  front: /homapge
admin_compact_mode: false
weight_select_max: 100
langcode: en
default_langcode: en
_core:
  default_config_hash: ...
mail_notification: ''

You can also run this in reverse by forcing your site to have a particular UUID. Taking the UUID from your system.site.yml file and applying it to the site can be done in the following way.

$ drush config-set "system.site" uuid "d6eb07f8-16d0-4c62-8fac-7e1cc2cc7046"

Do you want to update uuid key in system.site config? (yes/no) [yes]:
 > yes

Either mechanism will then allow you to import your configuration as normal.

Comments

I would not advise to do this. I'm not sure if it works on Drupal 8, but it definitely does NOT work on Drupal 9+ websites. I attempted to do this on a new website I just created, to see if the process works. I exported the config of a Drupal 9 website I created a few weeks ago and imported it in the new Drupal 9 website, after changing the site ID in the exported config bundle.

What seems to have happened when I tried it:
Indeed, Drupal check the site ID system.site.yml file, but it also uses the IDs in every other files. If an entity exists in Drupal but is not present in the import (i.e. it can not find its ID in the import), Drupal will delete the entity on the website. Since every single entities in Drupal have a different ID from the one in the import, Drupal attempts to delete every single entities before creating the new one. Unfortunately, Drupal can't function without any entities, so it dies and can't perform the import, leaving you with a broken website.

Permalink

Thanks for the information Gael.

I wonder if the effect you are seeing in Drupal 9+ is something do to with Configuration 2.0? Sounds like not only would you need to alter the main site ID, but also the uuid of every item of configuration in your site.

I have to admit that this technique is a bit of an edge case, but it sometimes got me out of certain situations in Drupal 8. Situations created by certain local development environments that I wont mention here.

Name
Philip Norton
Permalink

Just ran on a new Drupal 9 install as part of trying to instal a themeforrest theme.  Found the same problem as commented by Gael. 

In th eINSTALL directory of the unzipped theme is 485 yml config files. 
How is one supposed to import the config?

 

 

Permalink

To the hashbangcode.com webmaster, Thanks for the well-written and informative post!

Permalink

Add new comment

The content of this field is kept private and will not be shown publicly.
CAPTCHA
3 + 2 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.