<p>I'm trying to get a live site running locally (using DDEV) and having trouble importing the database. The database is an export from the live site (which is running and has been for a short time).</p>
<p>When importing the exported ZIP (also tried the SQL file inside the ZIP) we (it happens to colleagues too) get an error of <code>Duplicate entry '2022' for key 'categorygroups_sites.PRIMARY'</code></p>
<p>Initially the error was in <code>assets.PRIMARY</code> but I've slowly removed the <code>INSERT</code> statements to narrow the problem down.</p>
<p>I noticed on the <code>INSERT</code> statement that the <code>VALUES</code> don't match up with the column e.g.:</p>
<pre><code>INSERT INTO `categorygroups_sites` VALUES
('2022-11-07 16:50:49','2022-11-07 16:50:49',1,1,1,1,NULL,'48327b0b-baa8-4fb4-8f26-920e0b561f19','blog-categories/{slug}'),
</code></pre>
<p>The first value has a date, which starts with 2022 - that leads me to believe the <code>INSERT</code> command is using the first part of the date as the ID.</p>
<p>The start of the export has:</p>
<pre><code>CREATE TABLE `categorygroups_sites` (
  `id` int NOT NULL AUTO_INCREMENT,
  `groupId` int NOT NULL,
  `siteId` int NOT NULL,
  `hasUrls` tinyint(1) NOT NULL DEFAULT '1',
  `uriFormat` text CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci,
  `template` varchar(500) CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci DEFAULT NULL,
  `dateCreated` datetime NOT NULL,
  `dateUpdated` datetime NOT NULL,
  `uid` char(36) CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci NOT NULL DEFAULT '0',
  PRIMARY KEY (`id`),
</code></pre>
<p>Would I be right in thinking more than just the first values are in the wrong place?</p>
<p>We have a backup from about a week ago and that imports fine, but exports from the live site do not import.</p>
<p>Apologies if this is incorrect - it's what I've come to so far as to why we cannot import the database. Also comparing the export to another Craft3 site the other site's <code>INSERT</code> statement looks consistent with the column structure.</p>

CC BY-SA 4.0
2023-06-14T08:21:36.580Z
I've managed to get hold an export from just over a week ago, and the `INSERT` is a lot different: 
`INSERT INTO 'categorygroups_sites' VALUES
(1,1,1,1,'blog-categories/{slug}',NULL,'2022-11-07 16:50:49','2022-11-07 16:50:49','48327b0b-baa8-4fb4-8f26-920e0b561f19'),`
Jaytrix
CC BY-SA 4.0
2023-06-26T11:08:04.557Z
This issue has returned. We were able to solve the issue by updating Craft and all plugins - a db export after those updates was fine and the INSERT data was in the correct order for the columns. However! The same issue has returned, and there are no further updates to install.
Jaytrix
CC BY-SA 4.0
2023-08-25T05:17:21.587Z
Hi Jaytrix. We are experiencing a similar problem, when importing data from a production site (also using Docker). 

[ERROR in query 797] Duplicate entry '2019' for key 'PRIMARY' ignoring it generates hundreds more  Duplicate entry 'X' for key 'PRIMARY errors.

I was just wondering what versions of MySQL/MariaDB you are running on the production server vs your development machines, as we think the problem is related to dump being generated by MariaDB.
Iain Henderson
<craft3><database><mysql><import><export>
Duplicate entry '2022' for key 'categorygroups_sites.PRIMARY'
# Duplicate entry '2022' for key 'categorygroups_sites.PRIMARY'

(Asked by: username_0 on 2023-06-13)

I'm trying to get a live site running locally (using DDEV) and having trouble importing the database. The database is an export from the live site (which is running and has been for a short time).
When importing the exported ZIP (also tried the SQL file inside the ZIP) we (it happens to colleagues too) get an error of Duplicate entry '2022' for key 'categorygroups_sites.PRIMARY'
Initially the error was in assets.PRIMARY but I've slowly removed the INSERT statements to narrow the problem down.
I noticed on the INSERT statement that the VALUES don't match up with the column e.g.:
INSERT INTO `categorygroups_sites` VALUES
('2022-11-07 16:50:49','2022-11-07 16:50:49',1,1,1,1,NULL,'48327b0b-baa8-4fb4-8f26-920e0b561f19','blog-categories/{slug}'),

The first value has a date, which starts with 2022 - that leads me to believe the INSERT command is using the first part of the date as the ID.
The start of the export has:
CREATE TABLE `categorygroups_sites` (
  `id` int NOT NULL AUTO_INCREMENT,
  `groupId` int NOT NULL,
  `siteId` int NOT NULL,
  `hasUrls` tinyint(1) NOT NULL DEFAULT '1',
  `uriFormat` text CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci,
  `template` varchar(500) CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci DEFAULT NULL,
  `dateCreated` datetime NOT NULL,
  `dateUpdated` datetime NOT NULL,
  `uid` char(36) CHARACTER SET utf8mb3 COLLATE utf8mb3_unicode_ci NOT NULL DEFAULT '0',
  PRIMARY KEY (`id`),

Would I be right in thinking more than just the first values are in the wrong place?
We have a backup from about a week ago and that imports fine, but exports from the live site do not import.
Apologies if this is incorrect - it's what I've come to so far as to why we cannot import the database. Also comparing the export to another Craft3 site the other site's INSERT statement looks consistent with the column structure.

**Tags:** craft3, database, mysql, import, export
> **Comments:**
> **username_0**: I've managed to get hold an export from just over a week ago, and the `INSERT` is a lot different:  `INSERT INTO 'categorygroups_sites' VALUES (1,1,1,1,'blog-categories/{slug}',NULL,'2022-11-07 16:50:49','2022-11-07 16:50:49','48327b0b-baa8-4fb4-8f26-920e0b561f19'),`  
> **username_0**: This issue has returned. We were able to solve the issue by updating Craft and all plugins - a db export after those updates was fine and the INSERT data was in the correct order for the columns. However! The same issue has returned, and there are no further updates to install.  
> **username_1**: Hi Jaytrix. We are experiencing a similar problem, when importing data from a production site (also using Docker).   [ERROR in query 797] Duplicate entry '2019' for key 'PRIMARY' ignoring it generates hundreds more  Duplicate entry 'X' for key 'PRIMARY errors.  I was just wondering what versions of MySQL/MariaDB you are running on the production server vs your development machines, as we think the problem is related to dump being generated by MariaDB.  

---

## 0 answers

