Answers.Body: <p>If you'd rather write a Craft migration than directly modify the database, you can use the following:</p>
  <pre><code>    public function safeUp(): bool
      {
  
          $this-&gt;update(
              '{{%elements}}', // The table name
              ['type' =&gt; 'craft\\elements\\Entry'], // Column to update
              ['type' =&gt; 'craft\\models\\EntryDraft'] // Condition to filter which rows to update
          );
  
          return true;
      }
  </code></pre>
  <p>Which is equivalent to:</p>
  <pre><code>mysql&gt; UPDATE elements SET type = 'craft\\elements\\Entry' WHERE type = 'craft\\models\\EntryDraft'
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-12-20T16:55:09.610Z
Answers.LastActivityDate: 2023-12-20T16:55:09.610Z
Answers.UserDisplayName: Maddy Bishop-Van Horn
Answers.Body: <p>The class <a href="https://docs.craftcms.com/api/v3/craft-models-entrydraft.html" rel="nofollow noreferrer"><code>craft\models\EntryDraft</code> exists in Craft 3</a> but is gone in <a href="https://docs.craftcms.com/api/v4/" rel="nofollow noreferrer">Craft 4</a>. If you're getting this error, it means you still have some code in your project that was written for Craft 3 and needs to be updated for Craft 4. This can either be a site module or an external plugin. To find where this is coming from, check the error log, which should include a stack trace. If it doesn't, search for <code>EntryDraft</code> in the entire project (the <code>modules/</code> and <code>vendor/</code> folders are the most likely candidates) to find out where that class is referenced.</p>
  <p>If it's coming from a site module, you need to update the code in that module to work with Craft 4. If it's a plugin, update to the latest version and/or contact the maintainers to get this bug fixed. It's unlikely to be a plugin, because Composer wouldn't allow you to install Craft 4 as long as you have plugins installed that don't have a version that is compatible with Craft 4.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-02-14T15:52:07.667Z
Answers.Text: Thanks, MoritzLost! That has given me some good leads to follow. 
  Much appreciated :)
Answers.UserDisplayName: Martin
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-02-14T15:49:09.103Z
Answers.LastActivityDate: 2023-02-14T15:49:09.103Z
Answers.UserDisplayName: MoritzLost
Answers.Body: <p>@MoritzLost's answer is partly correct, but this particular error is not due to outdated code in your project.</p>
  <p>The <code>EntryDraft</code> class was <a href="https://github.com/craftcms/cms/blob/v3/CHANGELOG.md#deprecated-33" rel="nofollow noreferrer">deprecated in Craft 3.2.0</a>, but for some unknown reason (possibly due to a failed or incomplete migration from that era) a lot of installs that have since upgraded, still retain entries using that class for their <code>type</code> column in the <code>elements</code> table.</p>
  <p>After upgrading to Craft 4, attempting to load those entries will throw that exception, since the deprecated <code>EntryDraft</code> class was finally removed in 4.0 and Craft no longer knows how to deal with those entries.</p>
  <p><strong>The fix is to change any instances of <code>craft\models\EntryDraft</code> in the <code>elements</code> table, to <code>craft\elements\Entry</code> – for example via an <code>UPDATE</code> query:</strong></p>
  <pre class="lang-sql prettyprint-override"><code>UPDATE elements SET type = 'craft\\elements\\Entry' WHERE type = 'craft\\models\\EntryDraft'
  </code></pre>
  <p><em>If you're curious how many of these &quot;EntryDraft&quot; entries you have in your install, you can run the following SQL query (before updating the <code>type</code> column, of course):</em></p>
  <pre class="lang-sql prettyprint-override"><code>SELECT id FROM elements WHERE type='craft\\models\\EntryDraft'
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-02-15T08:52:18.193Z
Answers.Text: Ah, good to know! One of the reasons I'm not particularly fond of the element type being kept in the database … :s
Answers.UserDisplayName: MoritzLost
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-03-29T10:00:49.203Z
Answers.Text: Perfect! Thanks, Mats!
  This fixed my problem :)
Answers.UserDisplayName: Martin
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-02-14T17:56:28.813Z
Answers.LastActivityDate: 2023-12-06T19:38:36.993Z
Answers.LastEditDate: 2023-12-06T19:38:36.993Z
Answers.UserDisplayName: Mats Mikkel Rummelhoff
Body: <p>After upgrading to Craft 4 a few entries are throwing this error in the admin (Locally):</p>
  <blockquote>
  <p>craft\models\EntryDraft doesn’t exist or doesn’t extend/implement craft\base\ElementInterface</p>
  </blockquote>
  <p>Not all do this but a few do.</p>
  <p>Creating new entries works just fine and everything works otherwise.</p>
  <p>I tried pruning revisions and drafts. No luck.</p>
  <p>Deleted the rows in the drafts and revisions tables of the DB. No luck.</p>
  <p>I have an old DB and wonder if some old entries could be grumpy for whatever reason.</p>
  <p>I have requested an up-to-date DB I hope won't have this problem. But this will take a while to get.</p>
  <p>Has anyone else come across this issue?</p>
  
Tags: <craft4>
Title: Craft 4 upgrade. Entry throwing 'craft\models\EntryDraft doesn’t exist' error in admin
ThreadText: # Craft 4 upgrade. Entry throwing 'craft\models\EntryDraft doesn’t exist' error in admin
  
  (Asked by: username_0 on 2023-02-14)
  
  After upgrading to Craft 4 a few entries are throwing this error in the admin (Locally):
  
  > craft\models\EntryDraft doesn’t exist or doesn’t extend/implement craft\base\ElementInterface
  
  Not all do this but a few do.
  
  Creating new entries works just fine and everything works otherwise.
  
  I tried pruning revisions and drafts. No luck.
  
  Deleted the rows in the drafts and revisions tables of the DB. No luck.
  
  I have an old DB and wonder if some old entries could be grumpy for whatever reason.
  
  I have requested an up-to-date DB I hope won't have this problem. But this will take a while to get.
  
  Has anyone else come across this issue?
  
  **Tags:** craft4
  
  
  ---
  
  ## 3 answers
  
  ### Answer by username_3 on 2023-02-14. Score: 7 | Accepted answer
  
  @username_2's answer is partly correct, but this particular error is not due to outdated code in your project.
  
  The `EntryDraft` class was [deprecated in Craft 3.2.0](https://github.com/craftcms/cms/blob/v3/CHANGELOG.md#deprecated-33), but for some unknown reason (possibly due to a failed or incomplete migration from that era) a lot of installs that have since upgraded, still retain entries using that class for their `type` column in the `elements` table.
  
  After upgrading to Craft 4, attempting to load those entries will throw that exception, since the deprecated `EntryDraft` class was finally removed in 4.0 and Craft no longer knows how to deal with those entries.
  
  **The fix is to change any instances of `craft\models\EntryDraft` in the `elements` table, to `craft\elements\Entry` – for example via an `UPDATE` query:**
  
  ```sql
  UPDATE elements SET type = 'craft\\elements\\Entry' WHERE type = 'craft\\models\\EntryDraft'
  
  ```
  
  *If you're curious how many of these "EntryDraft" entries you have in your install, you can run the following SQL query (before updating the `type` column, of course):*
  
  ```sql
  SELECT id FROM elements WHERE type='craft\\models\\EntryDraft'
  
  ```
  
  > **Comments:**
  > **username_2**: Ah, good to know! One of the reasons I'm not particularly fond of the element type being kept in the database … :s  
  > **username_0**: Perfect! Thanks, username_3! This fixed my problem :)  
  
  ---
  
  ### Answer by username_1 on 2023-12-20. Score: 1
  
  If you'd rather write a Craft migration than directly modify the database, you can use the following:
  
  ```
      public function safeUp(): bool
      {
  
          $this->update(
              '{{%elements}}', // The table name
              ['type' => 'craft\\elements\\Entry'], // Column to update
              ['type' => 'craft\\models\\EntryDraft'] // Condition to filter which rows to update
          );
  
          return true;
      }
  
  ```
  
  Which is equivalent to:
  
  ```
  mysql> UPDATE elements SET type = 'craft\\elements\\Entry' WHERE type = 'craft\\models\\EntryDraft'
  
  ```
  
  
  ---
  
  ### Answer by username_2 on 2023-02-14. Score: 1
  
  The class [`craft\models\EntryDraft` exists in Craft 3](https://docs.craftcms.com/api/v3/craft-models-entrydraft.html) but is gone in [Craft 4](https://docs.craftcms.com/api/v4/). If you're getting this error, it means you still have some code in your project that was written for Craft 3 and needs to be updated for Craft 4. This can either be a site module or an external plugin. To find where this is coming from, check the error log, which should include a stack trace. If it doesn't, search for `EntryDraft` in the entire project (the `modules/` and `vendor/` folders are the most likely candidates) to find out where that class is referenced.
  
  If it's coming from a site module, you need to update the code in that module to work with Craft 4. If it's a plugin, update to the latest version and/or contact the maintainers to get this bug fixed. It's unlikely to be a plugin, because Composer wouldn't allow you to install Craft 4 as long as you have plugins installed that don't have a version that is compatible with Craft 4.
  
  > **Comments:**
  > **username_0**: Thanks, username_2! That has given me some good leads to follow.  Much appreciated :)  
  
  ---
  
  