1

I am currently running into a configuration importing error which seems caused from field collections.

Finalizing configuration synchronization.
The import failed due for the following reasons: Deleted and replaced configuration entity "field_collection.field_collection.field_lives_around"

I just started yesterday with this project. I created many fields and configurations; I am not using any custom code at all, for now.

What could go wrong?

The field collection contains a list (text) and a field from the Geolocation Field module.

2
  • 2
    Did you see this warning on the project page? "Paragraphs is likely to replace field collection for Drupal 8. Field collection is on its way to being deprecated. It is recommended to use paragraphs instead of field collection for Drupal 8 projects."
    – 4uk4
    Commented Jan 8, 2018 at 10:39
  • Wow ok i have not seen this for now. Thanks for the Info !
    – Sebastian
    Commented Jan 9, 2018 at 8:29

3 Answers 3

4

The error happens when entity you are trying to create already exists. Or the data changed while config import was in progress. See: ConfigImporter.php/checkOp().

If the target already exists, use the entity storage to delete it again, if is a simple config, delete it directly.

Running import twice may help, but obviously not at the same time, otherwise, you probably need to remove that field manually and try again.

This could be a bug of the module, as normally modules should have the following condition in place, e.g.

 /**
  * Implements hook_ENTITY_TYPE_insert().
  */
 function hook_ENTITY_TYPE_insert(RoleInterface $role) {
   if (\Drupal::isConfigSyncing()) {
     // Do not change data while config import in progress.
     return;
   }
   // ...
 }

Related bug: The group_roles field gets created too early during configuration sync.


Few hints:

  • In case you don't need the particular import, you can use Config Ignore to ignore it.
  • Try exporting the config first, then import again.
  • Try importing config individually first, file by file by using Drupal Console, e.g.

    drupal config:import:single --file=$PWD/config/sync/config_ignore.settings.yml 
    
0

You can also fix this issue by deleting the UUID from the config, both old and new.

  1. remove the UUID line from the element
  2. sql-sync the database to your local
  3. run config import
  4. run config export
  5. commit the changes to that config

Your config will have a new, valid UUID that you can commit to your repo and import on your remote.

0

We got the The import failed due to the following reasons: Deleted and replaced configuration entity ... error during the early development on a new project when a lot of entities and fields got created at once. The fix usually was to simply run drush cim again. So our updated build routine now has cim twice in it to circumvent failing builds.

drush cim -y || true
drush cim -y

Of course, finding and fixing the actual root cause that makes the import fail at the first place as suggested by @kenorb would be the preferred solution. But sometimes during early development you simply want things to move forward and the workaround above helped us to get that done.


Turned out that in my case a custom profile's implementation of hook_entity_bundle_create() where some defaults for newly created bundles were set has caused the error. Adding the following few lines in the beginning of these implementations fixed it for us. Credits: @hchonov

// If we are currently importing configuration we expect it to be complete and
// therefore we should not try to create configuration here as if we do and
// that configuration is also part of the import then the import will fail
// with "Deleted and replaced configuration entity "@name"".
// @see \Drupal\Core\Config\ConfigImporter::checkOp().
/** @var \Drupal\Core\Config\ConfigInstallerInterface $config_installer */
$config_installer =  \Drupal::service('config.installer');
if ($config_installer->isSyncing()) {
  return;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.