16

On Drupal 8.1 I keep running in those kind of messages when I try to activate a custom module or a custom feature that makes some modification to the basic page. (add fields).

It is really annoying...

Steps:

  • Clear database entirely
  • go to /install.php and choose Standard profile
  • Now that the site is running go to Extend
  • Select Feature - Basic page

Result:

Unable to install Feature - Basic Page, core.base_field_override.node.page.promote, core.entity_form_display.node.page.default, core.entity_view_display.node.page.default, core.entity_view_display.node.page.teaser, field.field.node.page.body, node.type.page already exist in active configuration.

Well yeah... that is what I want to do: Change those default settings!

Expexted:

Be able to install my feature that makes some modifications to the basic page.

My Feature

Here is my Feature create with the Features module

It basically adds two fields, banner_image and background_image to the basic page

Files:

config
    install
        core.base_field_override.node.page.changed.yml
        core.base_field_override.node.page.created.yml
        core.base_field_override.node.page.promote.yml
        core.base_field_override.node.page.status.yml
        core.base_field_override.node.page.sticky.yml
        core.base_field_override.node.page.title.yml
        core.base_field_override.node.page.uid.yml
        core.entity_form_display.node.page.default.yml
        core.entity_view_display.node.page.default.yml
        core.entity_view_display.node.page.teaser.yml
        field.field.node.page.body.yml
        field.field.node.page.field_banner_image.yml
        field.field.node.page.field_image.yml
        field.storage.node.field_banner_image.yml
        language.content_settings.node.page.yml
        node.type.page.yml
feature_basic_page.features.yml
feature_basic_page.info.yml

Why this simple thing is not supported? Is it a bug? What should I do to be able to use my feature?

2
  • 1
    Use drupal EasyInstall module which is used to remove active configurations – Karthikeyan Manivasagam Aug 24 '17 at 10:45
  • 1
    +1 interesting module - worth a look - thank you @KarthikeyanManivasagam – therobyouknow Sep 30 '18 at 22:02
31

With Drush, you can run drush config-delete module_name.settings to delete the configuration causing the error.

4
  • I also discovered during my epic battle against Drupal that you can move those configs in a optional/ folder to make it shut up. But I am not sure of all the implications... – Guillaume Bois May 26 '17 at 19:05
  • @GuillaumeBois : the implications are that these optionnal configurations would be ignored if already installed, or if dependencies are not met. So, it can lead to further problems if the configuration is necessary for the module to work. – Renrhaf Nov 29 '17 at 23:13
  • 1
    if you are not sure what "settings" do you have to delete, you should run "drush config-list" to get the exact name of the configuration – Jorge Valvert Jul 16 '19 at 11:00
  • doesn't work with configs which depends on language, for example config that name is like language/fr/module_name.settings – MiharbKH May 7 '20 at 16:27
5

Use the Easy Install module to purge the active configuration without using the Devel module or Drush. It works even if you have missed out the optional folder and the enforced option in the module's configuration files.

A module built to resolve and avoid the error "Unable to install already exists active configuration" when re installing/un installing the drupal 8 modules , it works even if the module's configs not contains enforced in yml and not added configs in optional folder. It purge the active configuration object of uninstalled modules and helps to remove configuration object while uninstalling a module without using Drush / Devel / Drupal Console / Features Modules.

0
4

For a Pantheon site, I used the following Drush commands.

  • On the Pantheon site, drush @pantheon.SITENAME.ENVNAME config-delete ERRORNAME
  • On the local site, drush config-delete ERRORNAME
3

This thing is not supported because a module may not replace a config entity that already exists with install config.

To add form and view mode configurations for an already existing node type, you have to implement this in code in hook_install().

Or you have to delete the node type first on your site, but then you also have to delete the content.

And no, this is not a bug, this is how it is defined to prevent loss of configuration.

4
  • This is very sad. In D7 this was possible (add fields to a basic page through a Feature). I still think it should be in D8 too. You say it is to prevent loss of configuration, but in reality, it simply adds configurations (fields, weight, label, etc.). Note that I also had this problem with my own custom modules. – Guillaume Bois Jul 25 '16 at 12:04
  • No, it doesn't just add. the view and form displays are shared across all fields of a single node type. what happens if two modules try to add that file, who's going to win? What happens about existing fields that already are on the page type? what if the basic node type exists but with different settings than in your field? The behavior scenarios like that is not defined. For a standalone feature, you're better off defining your own node type and to deploy this change on your own site, you don't need a feature module like in 7.x, you can just export the configuration and import it again. – Berdir Jul 25 '16 at 19:39
  • @berdir this is very interesting. So I am coming from this issue from trying to create a user profile feature that includes view and form notes. So are you saying this can't be done in features because the user content type will have already existed and the feature is trying to enable that? Is there some way to allow a feature to override this so that someone could enable a profile feature on an already existing site? – kaleemclarkson Mar 19 '17 at 18:13
  • @kaleemclarkson user is not a content type but an entity type. The only way to do it is what I described, you have to implement code in hook_install() of your feature module to set form and view display configuration. Or use the profile module and define your own profile type there. – Berdir Mar 19 '17 at 21:43
1

With drush en it works!

[profile_test]$ drush en feature_basic_page -y
The following extensions will be enabled: feature_basic_page
Do you really want to continue? (y/n): y    
feature_basic_page was enabled successfully.   [ok]

EDIT: there is a way better solution now, see: How do I remove a configuration object from the active configuration?

0

If you want to add configs to your custom module but they already exist in the active configuration, and for some reason you can't use drush to delete those configs (in my case because it's part of an install profile), and you are sure there won't be a problem with you overwriting the config, here's an approach to replacing those configs.

Add a new folder in your custom module, /config/hook_install and add your config .yml files in that folder, then in your module's hook_install.

use Drupal\Component\Serialization\Yaml;

/**
 * Implements hook_install().
 */
function mymodule_install() {

  // Replace these configs.  We're using code to do this, as they are already
  // installed.
  $config_files = [
    'language.types',
    'language.negotiation',
  ];

  foreach ($config_files as $config_id) {
    $raw_data = file_get_contents(drupal_get_path('module', 'mymodule') . '/config/hook_install/' . $config_id . '.yml');
    \Drupal::configFactory()->getEditable($config_id)
      ->setData(Yaml::decode($raw_data))
      ->save();
  }
}
0

Sometimes modules do not cleanly uninstall. Trying to re-enable a newer version would cause then this issue.

Do a DB backup first and run the following:

drush @site.env sqlq 'DELETE FROM config WHERE name LIKE "%module_name%";'
1
  • How to do this in case of a multi-site database? – Tanvir Ahmad Sep 15 '20 at 7:25
0

Let’s say that you don’t want to lose your settings for the module that somehow — on it's own — decided to become disabled. Do this:

(optional)

a) Backup your whole database. Put that someplace safe, just in case! ;-)

mysqldump -u {db_user} -p{db_pass} {database_name} > maybe-horrible-things-will-happen.sql
# HINT: no space after "-p" 

b) Backup your whole Drupal config:

drush config:export --destination=/some/path/where/this-folder-will-be-created

Your sites current configuration will get dumped into this-folder-will-be-created.

SEE: https://drushcommands.com/drush-9x/config/config:export/ for more info.

ASIDE: a and b aren’t really optional ... because Drupal 8 does bad things, for no good reason, all the time; you better have a backup!

(END optional)

STEP 1) Tell drush to open the config file for core.extension:

drush config:edit core.extension

ASIDE: This uses whatever editor your shell has set for the VISUAL environment var; mine is: VISUAL=vim

STEP 2) Add the missing keys under the module key. Here's an example:

module:
  commerce_square: -2
  action: 0
  address: 0
  # ... [lots of others] ...
  draggableviews: 0
  # ... [lots of others] ...
  media: 0 
  # ... [lots of others] ...
  site_settings: 0 
  # ... [lots of others] ...
  scss_compiler: 1
  views: 10
  demo_commerce: 1000
theme:
  bootstrap: 0

STEP 3) Save your edits and drush will proceed to do some horrifying Drupaly voodoo that magically re-enables your modules without losing your work.

ASIDE: I'm pretty sure that the : 0 but is the module weight because of the last entries in my config. I left three examples: scss_compiler, views, and demo_commerce, to illustrate the point.

Errors I saw.

If drush spits out an error like...

[error]  Drupal\Core\Config\ConfigImporterException: There were errors validating the config synchronization.                                                                                               
  Configuration <em class="placeholder">views.view.product_sorter</em> depends on the <em class="placeholder">DraggableViews</em> module that will not be installed after import. 

... then you'll need to add that key under module: also. I was trying to save site_settings and had no idea that draggableviews and media has also decided to go on holiday.

After adding media and saving the edit again, then I got the notification for draggableviews. Then after adding both media and draggableviews in the next go around, other bad things happened; read on...

If drush spits out an error like...

Table 'draggableviews_structure' already exists.

... then you might have to backup that table, delete the modules tables, and try again.

ASIDE: You can find out what the tables are for a given module by examining it's hook_schema() implementation, within it's module_name.install file. For example, the draggableviews.install file has this entry:

/**
 * Implements hook_schema().
 */
function draggableviews_schema() {
  $schema['draggableviews_structure'] = [
  //...
}

I didn't end up having to do that for the draggableviews_structure table, but here's how you'd go about that unpleasant task:

  1. Dump the modules tables, then after you're sure you have the modules data, drop the modules tables.
mysqldump -u {db_user} -p{db_pass} {database_name} draggableviews_structure > draggableviews_structure.sql
mysql -u {db_user} -p{db_pass} {database_name} -e 'drop table draggableviews_structure'
  1. re-edit the core.extension config; STEPs 1–3 above.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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