I have Rules as a part of a installation profile and some modules that have rules as features. When installing this profile I get the error:
"SQLSTATE[HY000]: General error: 1364 Field 'plugin' doesn't have a default value".

The fix for this is to define in the schema the default value, see the patch in comments.

This has been reported before: #1412448: Error using update.php - Field 'plugin' doesn't have a default value: INSERT INTO {rules_config}, but my profile does not have any commerce modules and there is a easy fix.

CommentFileSizeAuthor
#1 rules-schema-fix-1952170-1.patch872 bytesfluffy
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

fluffy’s picture

The patch, adds default value for plugins in the schema.

fluffy’s picture

Status: Active » Needs review

Status: Needs review » Needs work

The last submitted patch, rules-schema-fix-1952170-1.patch, failed testing.

ohthehugemanatee’s picture

I encountered this problem myself, and discovered the root of it (for me). If you have this problem, please post an export of your rule here!

Here was my rule:

function my_feature_default_rules_configuration() {
  $items = array();
  $items['rules_login_redirect_resume_search'] = entity_import('rules_config', '{ "rules_login_redirect_resume_search" : {
      "LABEL" : "login redirect (resume-search)",
      "PLUGIN" : "reaction rule",
      "WEIGHT" : "3",
      "TAGS" : [ "login" ],
      "REQUIRES" : [ "rules", "context_rules" ],
      "ON" : [ "user_login" ],
      "IF" : [
        { "user_has_role" : {
            "account" : [ "account" ],
            "roles" : { "value" : { "5" : "5" } },
            "operation" : "OR"
          }
        },
        { "rules_condition_context_rules_context_isset" : { "context" : "resume_search" } }
      ],
      "DO" : [
        { "drupal_message" : {
            "message" : "This feature is only available to Recruiters.",
            "repeat" : 0
          }
        }
      ]
    }
  }');

The issue isn't that PLUGIN wasn't declared, it's that the rule label included special characters, and was double-quoted in the Feature export. It tried to evaluate the braces, and I suppose couldn't distinguish that PLUGIN was the next key in the array.

So for me the solution was simply to rename the Rule to avoid the braces (I went with "login redirect for resume-search") and re-export. Or just edit the code and revert. I would expect this to be a problem anywhere that Rules allows special characters which are double quoted in Features. So check your export!

hefox’s picture

Title: Install: SQLSTATE[HY000]: General error: 1364 Field 'plugin' doesn't have a default value » Exported rules have invalid json
Version: 7.x-2.2 » 7.x-2.x-dev

The general issue seems to be invalid json. Havent checked that the importing with latest -dev of entity/rules produces the invalid json, but trying to import the invalid json does and only fails at this stage.

So two problems

1) no warnings about invalid json
2) the export of invalid json

My json was not importing correctly due to a comma

{ "rules_email_editor_on_needs_review" : {
      "LABEL" : "Email Editor On Needs Review",
      "PLUGIN" : "reaction rule",
      "REQUIRES" : [ "workbench_moderation", "rules" ],
      "ON" : [ "workbench_moderation_after_moderation_transition" ],
      "IF" : [
        { "contents_current_state" : { "node" : [ "node" ], "moderation_state" : "needs_review" } },
        { "contents_previous_state" : { "node" : [ "node" ], "moderation_state" : "draft" } },; THIS COMMA HERE
      ],
      "DO" : [
        { "mail" : {
            "to" : [ "site:opensf-workbench-editors-emails" ],
            "subject" : "A content item [node:content-type] [node:title] is ready for review",
            "message" : "[node:content-type] [node:title] has been set to needs review on on [site:current-date] by [site:current-user].\\r\\n\\r\\n[node:url]",
            "language" : [ "" ]
          }
        }
      ]
    }
  }
TR’s picture

Issue summary: View changes
Status: Needs work » Postponed (maintainer needs more info)

This issue is very old - is this still a problem with the current version of Rules? There haven't been any further comments or reports of a similar problem for >5 years now.

I looked at this a little, and tried to reproduce some of it.

Specifically, for comment #5 there were two problems mentioned:

1) no warnings about invalid json
2) the export of invalid json

For 1), if I try to import the rule from #5, which has invalid JSON, then I AM given an error that the Rule contains invalid JSON.
For 2), when I export a rule with multiple conditions it does NOT add that extra comment that causes problems for you.

Comment #4 says that "LABEL" : "login redirect (resume-search)", is invalid JSON because of the braces inside the label text. But that's not so - braces are allowed inside double-quoted strings like this. If that causes an error with Features, then that's a Features issue.

As for the original post, reading through the linked issues in the commerce_recurring queue, it seems that individuals have traced their particular problem to other things, such as a missing dependency. Likewise, @fago looked into the need for a default value in #1046250: Plugin field in hook_schema lacks default value and concluded it wasn't required.

Rules uses the Entity API to generate the JSON for the export, and the Entity API uses the core Drupal function drupal_export_json(). So while there could conceivably be a problem with how Rules or the Entity API passes data to drupal_export_json(), if there are any syntax errors in the resulting JSON that really amounts to a bug in that core Drupal function.

If this is still a problem, I need to see specific steps to reproduce the issue. If it can't be reproduced, then we have no assurance that any change to Rules actually 'fixed' the problem.

TR’s picture

Status: Postponed (maintainer needs more info) » Closed (cannot reproduce)

No further information provided.