<p>This has been resolved by Craft in 3.7.29 on 1/18/2022.</p>
<ul>
<li>The content in the resourcepaths table is now excluded from database backups by default.</li>
</ul>

CC BY-SA 4.0
2022-02-02T19:51:27.553Z
Oh, got it, but i'm using a custom database backup statement. I need to revise that to exclude the content, apparently.
adrienne
CC BY-SA 4.0
2022-02-02T15:40:19.603Z
2022-02-02T15:40:19.603Z
jpwdesigns
<p>I am seeing this issue as well, specifically with the <code>resourcepaths</code> table. I had to do some nonsense with SED in order to get this working.</p>
<p>This is an extremely hacky solution, but here's what i did:</p>
<ol>
<li>First replace the PRIMARY KEY declaration in the SQL file with a garbage column (this was easier than removing the PK declaration plus the trailing comma):</li>
</ol>
<pre><code>sed -i 's/PRIMARY KEY [(]`hash`[)]/`temp` varchar(255) COLLATE utf8_unicode_ci/g' filename.sql
</code></pre>
<ol start="2">
<li>Then fix the <code>INSERT</code> statement for the table so it doesn't choke on the number of columns:</li>
</ol>
<pre><code>sed -i 's/INSERT INTO `resourcepaths`/INSERT INTO `resourcepaths` (`hash`, `path`)/g' new-haven-independent--2022-02-01-025526--v3.7.30.1.sql
</code></pre>
<ol start="3">
<li>Import your database.</li>
<li>Run the following <em>as a transaction</em> (it will not work otherwise):</li>
</ol>
<pre><code>START TRANSACTION;  
TRUNCATE TABLE resourcepaths;
ALTER TABLE resourcepaths drop column `temp`, add primary key(`hash`);
COMMIT;
</code></pre>
<p>As i say, this is an ugly <em>ugly</em> hack, but until they fix the issue, it worked for me.</p>

CC BY-SA 4.0
2022-02-01T04:58:28.457Z
2022-02-01T05:46:51.227Z
2022-02-01T05:46:51.227Z
adrienne
<p>If you have a duplicate key in there, it means that you could be missing the PRIMARY KEY on the <code>hash</code> column of your <code>resourcepaths</code> table.</p>
<p><a href="https://plugins.craftcms.com/fix-fks" rel="nofollow noreferrer">Install this plugin</a> in production.</p>
<p>Run Utilities → Caches and clear your Control panel resources, next, run Utilities → Fix FKs.</p>
<p>Now re-export your live DB and try to import it again.</p>
<p>If this doesn't solve the issue, make sure you are importing in <strong>an empty</strong> database.</p>

CC BY-SA 4.0
2022-01-03T16:21:41.953Z
There is no duplicate key.  You can look in the sql file and verify that. The SQL dumps also include a drop table if exists statement so the tables are all empty. If there is a problem with the SQL file, then it is a problem with CraftCMS's export process. This doesn't solve my problem.

Furthermore I can sometimes get the sql files to import if I do not use craft's command line db/restore and instead use just a linux command line command to import. Meaning, perhaps theres a problem with Craft? Or how php is interacting with mysql?
jpwdesigns
CC BY-SA 4.0
2022-01-03T16:34:00.490Z
I will try those things and let you know if it helps. @Oli
jpwdesigns
CC BY-SA 4.0
2022-01-03T16:44:49.537Z
If this doesn't work, make sure you are importing in an empty database, not _on top_ of an existing one :)
Oli
CC BY-SA 4.0
2022-01-03T17:22:10.957Z
Importing into an empty database is not a solution for me. Thank you for the reply but I still need to consider this unresolved.
jpwdesigns
CC BY-SA 4.0
2022-01-04T15:30:16.357Z
Run Utilities → Caches and clear your Control panel resources, next, run Utilities → Fix FKs. Seems to be doing the trick for me. Thank you
jpwdesigns
CC BY-SA 4.0
2022-01-03T16:15:08.277Z
2022-01-03T16:48:48.427Z
2022-01-03T16:48:48.427Z
Oli
<p>On the latest version of Craft, (3.7.25.1) after updating I'm getting regular errors when importing a backup into production servers during deployments.  Here is an example of the error:</p>
<pre><code>error: The shell command &quot;mysql --defaults-extra-file=&quot;/tmp/ewpqcugdwoke.cnf&quot; craft3 &lt; &quot;/var/www/craft3/mysql_backups/backup.sql&quot;&quot; failed with exit code 1: ERROR 1062 (23000) at line 5894: Duplicate entry '2da4a0e' for key 'PRIMARY'
</code></pre>
<p>When I search for the entry reported in the error, in this case: '2da4a0e', I'll always find the string in the SQL file INSERT INTO <code>craft_resourcepaths</code> VALUES ... section. There is never a duplicate in the sql file so why am I seeing these errors and how can this be fixed?</p>
<p>Example of the import command:</p>
<pre><code>php craft db/restore /var/www/craft3/mysql_backups/backup.sql --interactive=0
</code></pre>
<p>If I manually import the db it works. For example:</p>
<pre><code>sudo mysql craft3 &lt; mysql_backups/backup.sql 
</code></pre>

CC BY-SA 4.0
2022-02-07T13:29:41.883Z
For what it's worth - I don't believe this is an issue specifically with the Craft restore command. I've frequently seen this restoring a dump with the mysql command, even after dropping tables. Only ever on this table though, so I learned a good while ago to exclude it from the dump.
Wallace
<error><import>
Importing DB Errors: craft_resourcepaths
# Importing DB Errors: craft_resourcepaths

(Asked by: username_0 on 2021-12-16)

On the latest version of Craft, (3.7.25.1) after updating I'm getting regular errors when importing a backup into production servers during deployments.  Here is an example of the error:
error: The shell command "mysql --defaults-extra-file="/tmp/ewpqcugdwoke.cnf" craft3 < "/var/www/craft3/mysql_backups/backup.sql"" failed with exit code 1: ERROR 1062 (23000) at line 5894: Duplicate entry '2da4a0e' for key 'PRIMARY'

When I search for the entry reported in the error, in this case: '2da4a0e', I'll always find the string in the SQL file INSERT INTO craft_resourcepaths VALUES ... section. There is never a duplicate in the sql file so why am I seeing these errors and how can this be fixed?
Example of the import command:
php craft db/restore /var/www/craft3/mysql_backups/backup.sql --interactive=0

If I manually import the db it works. For example:
sudo mysql craft3 < mysql_backups/backup.sql

**Tags:** error, import

> **Comments:**
> **username_1**: For what it's worth - I don't believe this is an issue specifically with the Craft restore command. I've frequently seen this restoring a dump with the mysql command, even after dropping tables. Only ever on this table though, so I learned a good while ago to exclude it from the dump.  

---

## 3 answers

### Answer by username_0 on 2022-02-02. Score: 1 | Accepted answer

This has been resolved by Craft in 3.7.29 on 1/18/2022.

* The content in the resourcepaths table is now excluded from database backups by default.

> **Comments:**
> **username_2**: Oh, got it, but i'm using a custom database backup statement. I need to revise that to exclude the content, apparently.  

---

### Answer by username_2 on 2022-02-01. Score: 1

I am seeing this issue as well, specifically with the resourcepaths table. I had to do some nonsense with SED in order to get this working.
This is an extremely hacky solution, but here's what i did:

First replace the PRIMARY KEY declaration in the SQL file with a garbage column (this was easier than removing the PK declaration plus the trailing comma):

sed -i 's/PRIMARY KEY [(]`hash`[)]/`temp` varchar(255) COLLATE utf8_unicode_ci/g' filename.sql


Then fix the INSERT statement for the table so it doesn't choke on the number of columns:

sed -i 's/INSERT INTO `resourcepaths`/INSERT INTO `resourcepaths` (`hash`, `path`)/g' new-haven-independent--2022-02-01-025526--v3.7.30.1.sql


Import your database.
Run the following as a transaction (it will not work otherwise):

START TRANSACTION;  
TRUNCATE TABLE resourcepaths;
ALTER TABLE resourcepaths drop column `temp`, add primary key(`hash`);
COMMIT;

As i say, this is an ugly ugly hack, but until they fix the issue, it worked for me.


---

### Answer by username_3 on 2022-01-03. Score: 1

If you have a duplicate key in there, it means that you could be missing the PRIMARY KEY on the `hash` column of your `resourcepaths` table.

[Install this plugin](https://plugins.craftcms.com/fix-fks) in production.

Run Utilities → Caches and clear your Control panel resources, next, run Utilities → Fix FKs.

Now re-export your live DB and try to import it again.

If this doesn't solve the issue, make sure you are importing in **an empty** database.

> **Comments:**
> **username_0**: There is no duplicate key.  You can look in the sql file and verify that. The SQL dumps also include a drop table if exists statement so the tables are all empty. If there is a problem with the SQL file, then it is a problem with CraftCMS's export process. This doesn't solve my problem.  Furthermore I can sometimes get the sql files to import if I do not use craft's command line db/restore and instead use just a linux command line command to import. Meaning, perhaps theres a problem with Craft? Or how php is interacting with mysql?  
> **username_0**: I will try those things and let you know if it helps. @username_3  
> **username_3**: If this doesn't work, make sure you are importing in an empty database, not _on top_ of an existing one :)  
> **username_0**: Importing into an empty database is not a solution for me. Thank you for the reply but I still need to consider this unresolved.  
> **username_0**: Run Utilities → Caches and clear your Control panel resources, next, run Utilities → Fix FKs. Seems to be doing the trick for me. Thank you  

---

