Answers.Body: <p>I figured it out. I'm not sure understand the why of it. But here is the how:</p>
  
  <pre><code>$product-&gt;setFieldValue('components', []);
  Craft::$app-&gt;elements-&gt;saveElement($product);
  </code></pre>
  
  <p>I guess setFieldValue() does some other stuff in it that the magic methods do not.</p>
  
  <p>The more you know! :)</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-06-27T20:09:46.007Z
Answers.Text: What the freaking heck. That worked. Thanks!
Answers.UserDisplayName: Fred
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-12-21T00:24:31.167Z
Answers.LastActivityDate: 2018-12-21T00:24:31.167Z
Answers.UserDisplayName: Tony DeStefano
Body: <p>I'm using a migration script to clear out the values for a field on one of my entries. The field is an Entry Field and is not required.</p>
  
  <p>So I do this:</p>
  
  <pre><code>$product-&gt;components = [];
  Craft::$app-&gt;elements-&gt;saveElement($product);
  </code></pre>
  
  <p>But I get this error:</p>
  
  <blockquote>
    <p>Argument 1 passed to craft\fields\BaseRelationField::_all() must
    implement interface craft\elements\db\ElementQueryInterface, array
    given, called in
    /var/www/html/vendor/craftcms/cms/src/fields/BaseRelationField.php on
    line 382</p>
  </blockquote>
  
  <p>I can clear out other fields, even entry fields, just fine. But this particular one gives me this error every time.</p>
  
  <p>I've also tried the following:</p>
  
  <pre><code>$product-&gt;components = null;
  Craft::$app-&gt;elements-&gt;saveElement($product);
  </code></pre>
  
  <p>And:</p>
  
  <pre><code>$product-&gt;components = false;
  Craft::$app-&gt;elements-&gt;saveElement($product);
  </code></pre>
  
  <p>Any ideas?</p>
  
Tags: <entries><craft3><migration>
Title: Error clearing a field via migration script
ThreadText: # Error clearing a field via migration script
  
  (Asked by: username_0 on 2018-12-20)
  
  I'm using a migration script to clear out the values for a field on one of my entries. The field is an Entry Field and is not required.
  
  So I do this:
  
  ```
  $product->components = [];
  Craft::$app->elements->saveElement($product);
  
  ```
  
  But I get this error:
  
  > Argument 1 passed to craft\fields\BaseRelationField::\_all() must
  > implement interface craft\elements\db\ElementQueryInterface, array
  > given, called in
  > /var/www/html/vendor/craftcms/cms/src/fields/BaseRelationField.php on
  > line 382
  
  I can clear out other fields, even entry fields, just fine. But this particular one gives me this error every time.
  
  I've also tried the following:
  
  ```
  $product->components = null;
  Craft::$app->elements->saveElement($product);
  
  ```
  
  And:
  
  ```
  $product->components = false;
  Craft::$app->elements->saveElement($product);
  
  ```
  
  Any ideas?
  
  **Tags:** entries, craft3, migration
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2018-12-21. Score: 5 | Accepted answer
  
  I figured it out. I'm not sure understand the why of it. But here is the how:
  
  ```
  $product->setFieldValue('components', []);
  Craft::$app->elements->saveElement($product);
  
  ```
  
  I guess setFieldValue() does some other stuff in it that the magic methods do not.
  
  The more you know! :)
  
  > **Comments:**
  > **username_1**: What the freaking heck. That worked. Thanks!  
  
  ---
  
  